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

--------------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);*/

}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值