[UE4]Server RPC 函数的正确定义方式

v4.7版本之后的定义方式:

如果函数定义为UFUNCTION(Server, Reliable, WithValidation),需要同时为其定义_Validate_Implementation两个函数
头文件:

UFUNCTION(Server, Reliable, WithValidation)
void ServerMove(FVector Velocity, bool bSweep); 
virtual bool ServerMove_Validate(FVector Velocity, bool bSweep);
virtual void ServerMove_Implementation(FVector Velocity, bool bSweep);

CPP文件:原函数名不用实现,但_Validate_Implementation必须实现

bool ASWeapon::ServerHandleFiring_Validate()
{
	return true;//默认返回为true
}

void ASWeapon::ServerHandleFiring_Implementation()
{
	//具体的函数逻辑
}

 

猜你喜欢

转载自aigo.iteye.com/blog/2273433