您的位置:首页 > 理论基础 > 计算机网络

UE4.12.5-C++ 网络复制 Net/UnrealNetwork.h

2016-09-05 17:27 816 查看
--------------2016.9.5----------------李明阳-----------------------

UE4.12.5-C++ 网络复制 Net/UnrealNetwork.h

#include"Net/UnrealNetwork.h"

使用网络复制需要在项目名称头文件夹中#include"Net/UnrealNetwork.h"

参考SurvivalGame.h

// Thisis NOT included by default in an empty project! It's required for replicationand setting of the GetLifetimeReplicatedProps
#include"Net/UnrealNetwork.h"

 

Include后声明网络复制变量或函数

编译也会提示“无法解析的外部符号”,如下:

Character.h

    /* Is character currently performing a jump action. Resets on landed. 
*/
    UPROPERTY(Transient, Replicated)
    bool bIsJumping;

 

    UFUNCTION(Reliable, Server, WithValidation)
    voidServerDropWeapon();

并不是上面的代码写得不对,编译不过是因为使用网络复制还需要一个函数GetLifetimeReplicated,DOREPLIFETIME。

以变量bool bIsJumping;为例,cpp中需要加如下代码可成功编译。

Character.cpp

voidASCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>&
OutLifetimeProps)
const
{
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 
    // Value is already updated locally, skip in replication step
    DOREPLIFETIME_CONDITION(ASCharacter, bIsJumping,
COND_SkipOwner);
    /* If we did not display the current inventory on the player mesh we couldoptimize replication by using this replication condition. */
    /* DOREPLIFETIME_CONDITION(ASCharacter, Inventory, COND_OwnerOnly);*/
}

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息