ue4 rpc调用不起作用
2016-05-24 15:57
183 查看
在项目开发过程中,遇到了一个问题,在Pawn派生类的蓝图中,在Event Possessed事件处理过程中,出发一个自定义事件(记为CustomEvent),该自定义事件标记为 Multicast,但是遇到一个奇怪的问题,当地客户端登陆后,收不到CustomEvent事件,但是如果我在触发CustomEvent的时候加一个延迟,客户端就可以收到CustomEvent事件,这里很容易就联想,服务器和客户端需要等到一个时机以后才可以正常进行rpc调用。那这个具体的时机是什么呢,我们看源码来分析一下。
在调试源码的过程中,我发现第一次调用失败,是因为如下函数返回了:
void UIpNetDriver::ProcessRemoteFunction(class AActor* Actor, UFunction* Function, void* Parameters, FOutParmRec* OutParms, FFrame* Stack, class UObject* SubObject )
for (int32 i=0; i<ClientConnections.Num(); ++i)
{
Connection = ClientConnections[i];
if (Connection && Connection->ViewTarget)
{
服务器在处理远程调用时,遍历客户端连接,第一次调用CustomEvent时,Connection->ViewTarget是NULL,导致本次远程调用失败,那Connection->ViewTarget为什么会是NULL呢,继续分析发现Connection->ViewTarget是在如下函数中赋值的,
int32 UNetDriver::ServerReplicateActors(float DeltaSeconds)
但是只有在以下判断成功的情况下才进行,
AActor* OwningActor = Connection->OwningActor;
if (OwningActor != NULL && Connection->State == USOCK_Open && (Connection->Driver->Time - Connection->LastReceiveTime < 1.5f))
{
继续调试,发现第一次调用CustomEvent时,Connection->OwningActor是空的,间接导致Connection->ViewTarget为NULL
继续跟踪发现Connection->OwningActor被赋值的地方是在void APlayerController::SetPlayer( UPlayer* InPlayer )进行的,而其他客户端登陆时,服务器是在收到客户端的NMT_Join消息,会Spawn PlayerController,从而调用SetPlayer。
rpc不起作用的原因就在于在Pawn派生类的蓝图收到Possessed事件时,Connection->ViewTarget还没有被赋值
在调试源码的过程中,我发现第一次调用失败,是因为如下函数返回了:
void UIpNetDriver::ProcessRemoteFunction(class AActor* Actor, UFunction* Function, void* Parameters, FOutParmRec* OutParms, FFrame* Stack, class UObject* SubObject )
for (int32 i=0; i<ClientConnections.Num(); ++i)
{
Connection = ClientConnections[i];
if (Connection && Connection->ViewTarget)
{
服务器在处理远程调用时,遍历客户端连接,第一次调用CustomEvent时,Connection->ViewTarget是NULL,导致本次远程调用失败,那Connection->ViewTarget为什么会是NULL呢,继续分析发现Connection->ViewTarget是在如下函数中赋值的,
int32 UNetDriver::ServerReplicateActors(float DeltaSeconds)
但是只有在以下判断成功的情况下才进行,
AActor* OwningActor = Connection->OwningActor;
if (OwningActor != NULL && Connection->State == USOCK_Open && (Connection->Driver->Time - Connection->LastReceiveTime < 1.5f))
{
继续调试,发现第一次调用CustomEvent时,Connection->OwningActor是空的,间接导致Connection->ViewTarget为NULL
继续跟踪发现Connection->OwningActor被赋值的地方是在void APlayerController::SetPlayer( UPlayer* InPlayer )进行的,而其他客户端登陆时,服务器是在收到客户端的NMT_Join消息,会Spawn PlayerController,从而调用SetPlayer。
rpc不起作用的原因就在于在Pawn派生类的蓝图收到Possessed事件时,Connection->ViewTarget还没有被赋值
相关文章推荐
- STL之priority_queue
- UiAutomator简单实例----进入Settings->Language&input
- PriorityQueue详解
- juey点击tr选中里面的radio
- STL之queue
- easyui1.32 各种问题汇总
- 模拟实现英汉字典(使用key/value形式的哈希表)
- 国产数据连接池Druid
- 虚幻4 改变默认UI Disable的Shader
- Django中嵌入ueditor并改进SyntaxHighlighter
- LinkIssue: Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or cor
- 1017. Queueing at Bank (25)
- finished with non-zero exit value 2
- STL之deque
- KVC中setValuesForKeysWithDictionary:
- request threaded-only IRQs with IRQF_ONESHOT【转】
- Android高级UI GridView
- iOS-OC-UITableViewCell分割线自定义
- aidl.exe'' finished with non-zero exit value 1问题解决【转载】
- UICollectionViewLayout