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