c++ - 如何在 UE4 C++ 中使用参数将 UFunction 添加到接口的委托?
问题描述
我正在寻找在虚幻中使用网络套接字。我正在关注此处找到的教程:Web Socket Tutorial
最值得注意的是,我试图在连接之前绑定到事件。在示例中,他们使用.AddLambda
但是,我想尝试使用.AddUFunction
. 该函数似乎接受了对象、函数名和VarTypes ...types
. 我似乎无法弄清楚使用参数的代表的最后一个参数是什么。(至少我相信这是问题所在)函数本身具有正确的签名并匹配我想要绑定的委托。
这是我到目前为止所拥有的:
void AWebSocketController::CreateWebSocket(FString ServerUrl, FString ServerProtocol)
{
Socket = FWebSocketsModule::Get().CreateWebSocket(ServerUrl, ServerProtocol);
// We bind to the events
Socket->OnConnected().AddUFunction(this, FName("OnSocketConnection"));
Socket->OnConnectionError().AddUFunction(this, FName("OnSocketConnectionError"));
Socket->OnClosed().AddUFunction(this, FName("OnSocketClosed"));
Socket->OnMessage().AddUFunction(this, FName("OnSocketReceiveMessage"));
Socket->OnMessageSent().AddUFunction(this, FName("OnSocketSentMessage"));
// And we finally connect to the server.
Socket->Connect();
}
它给了我以下错误消息:
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketClosed(int,class FString const &,bool)" (?OnSocketClosed@AWebSocketController@@QEAAXHAEBVFString@@_N@Z) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketConnection(void)" (?OnSocketConnection@AWebSocketController@@QEAAXXZ) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketConnectionError(class FString const &)" (?OnSocketConnectionError@AWebSocketController@@QEAAXAEBVFString@@@Z) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketReceiveMessage(class FString const &)" (?OnSocketReceiveMessage@AWebSocketController@@QEAAXAEBVFString@@@Z) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketSentMessage(class FString const &)" (?OnSocketSentMessage@AWebSocketController@@QEAAXAEBVFString@@@Z) already defined in WebSocketController.cpp.obj
函数定义:
void AWebSocketController::OnSocketConnection()
{
}
void AWebSocketController::OnSocketConnectionError(const FString& ErrorMessage)
{
}
void AWebSocketController::OnSocketClosed(int32 StatusCode, const FString& Reason, bool WasClean)
{
}
void AWebSocketController::OnSocketReceiveMessage(const FString& Message)
{
}
void AWebSocketController::OnSocketSentMessage(const FString& Message)
{
}
我以前从未遇到过这种情况.AddUFunction
,而且我似乎找不到任何如何使用它的示例。如果有人可以帮助我或指出我正确的方向,将不胜感激。
解决方案
推荐阅读
- python - 值错误'/anaconda3/lib/libpython3.7.dylib'不存在?
- deep-learning - 尝试运行深度学习测试代码后,我在 Pycham 中遇到错误
- python - 如何在python中修复“TypeError:'numpy.ndarray'对象不可调用”
- react-native - 强制方向为横向时反应本机相机崩溃
- asp.net-core - 登录后身份未重定向到返回 url
- python - BTC.COM API:HTTP 错误 414:请求 URI 太大
- javascript - 如何在 HTML 5 播放器中获得视频质量控制
- javascript - 查找在 word 包装元素中如何拆分行
- url - 从 Inno Setup Pascal 脚本中的 URL 解析主机名和协议
- java - CMAKE 找不到 JAVA