UE4动态委派ExcuteIfBound不执行我的函数


DECLARE_DYNAMIC_DELEGATE_OneParam(FTcpSocketDisconnectDelegate, int32, connectionID);
DECLARE_DYNAMIC_DELEGATE_OneParam(FTcpSocketConnectDelegate, int32, connectionID);
DECLARE_DYNAMIC_DELEGATE_TwoParams(FTcpSocketReceivedMessageDelegate, int32,connectionID, TArray<uint8>&, message);

我写了三个委托在我的类和一个绑定函数BindDynamic宏

FTcpSocketDisconnectDelegate disconnectDelegate;
disconnectDelegate.BindDynamic(this, &AGameTcpSocketConnection::OnDisconnected);
FTcpSocketConnectDelegate connectDelegate;
connectDelegate.BindDynamic(this, &AGameTcpSocketConnection::OnConnected);
FTcpSocketReceivedMessageDelegate receivedDelegate;
receivedDelegate.BindDynamic(this, &AGameTcpSocketConnection::OnMessageReceived);
disconnectDelegate.Execute(0);
connectDelegate.Execute(0);
TArray<uint8> message;
receivedDelegate.ExecuteIfBound(0, message);

但是Execute和ExecuteIfBound不起作用,函数没有被调用。我检查它在DebugGame模式,但它不工作我怎样才能弥补呢?请帮帮我。

FTcpSocketDisconnectDelegate disconnectDelegate;
FTcpSocketConnectDelegate connectDelegate;
FTcpSocketReceivedMessageDelegate receivedDelegate;
disconnectDelegate.AddDynamic(this, &AGameTcpSocketConnection::OnDisconnected);
connectDelegate.AddDynamic(this, &AGameTcpSocketConnection::OnConnected);
receivedDelegate.AddDynamic(this, &AGameTcpSocketConnection::OnMessageReceived);

if (disconnectDelegate.IsBound())
disconnectDelegate.Broadcast(0);
if (connectDelegate.IsBound())
connectDelegate.Broadcast(0);
TArray<uint8> message;
if (receivedDelegate.IsBound())
receivedDelegate.Broadcast(0, message);

最新更新