Hey guys,
I got a problem with an implemenation of a replication. I tried figuring out the problem by reading through the docu and searching through the AnswersHub and there are plenty of answers, but they are all done within Blueprints, so they don’t really help me. What I have is the “3rd Person”-Template and I want to make sure rotations of pawns get replicated to all clients. Therefore I declared the following functions in my
TauriCharacter.h
/** Turn Event, called when Mouse is moved */
void Turn(float Value);
UFUNCTION(Server, Reliable, WithValidation)
void ServerTurnPlayer(float Value);
virtual void ServerTurnPlayer_Implementation(float Value);
virtual bool ServerTurnPlayer_Validate(float Value);
Turn is called on
InputComponent->BindAxis(“Turn”, this, &ATauriCharacter::Turn);
further up in the code.
The implementation of that functions looks as follows:
void ATauriCharacter::Turn(float Value)
{
APawn::AddControllerYawInput(Value);
FRotator rot = FollowCamera->GetComponentRotation();
FRotator newRot(0.f, rot.Yaw - 90.f, 0.f);
GetMesh()->SetWorldRotation(newRot);
if (Role < ROLE_Authority)
{
ServerTurnPlayer(Value);
}
}
bool ATauriCharacter::ServerTurnPlayer_Validate(float Value)
{
return true;
}
void ATauriCharacter::ServerTurnPlayer_Implementation(float Value)
{
Turn(Value);
}
My problem now is, that when running one server and a client (not dedicated) I can see the replication is successful on the server, so the client does replicate it’s rotation to the server, which can actually see the rotation. The event is not send to all clients however. So I don’t see the replication on the client side.
I think the problem is, that I only let the function be called by the client who triggers the rotation as well as on the server, but not on the other clients. I tried different settings for UFUNCTION, such as setting NetMulticast instead of server. This leads VS2015 and UE4-Editor crashes. I’ve also looked into: https://answers.unrealengine.com/questions/142883/replication-actorpawn-rotation-in-c.html
But the answer in there is just suggesting to add the if-statement, which is already included in my code. So that doesn’t seem to be the problem. What am I missing here?
Cheers Max
P.S.: Here’s an webm of what it looks like atm: https://www.mklingmann.com/files/webm/replication.webm