I am trying to make a Pawn that can be controlled by a player and have it’s movement replicated.
I don’t want to use Character pawn so please don’t suggest that.
I understand that Default Pawns don’t automatically handle replication like the character does and you need to handle the movement on the Server with RPCs.
In my DefaultPawn class I have overriden the MoveForward function and added a Server/Client check to the move forward function. When the Client calls MoveForward it is correctly recognizing that it is the client and calling the RPC on the server. The server then runs the MoveForward function, I have debugged the function and it is definitely being called on the Server with the correct values.
The weird thing is nothing happens on the Server or Client when the MoveForward function called on the Server even though it is definitely being called.
Why does AddMovementInput() work when called on the Client but do absolutely nothing when called on the Server?
MoveForaward function and it’s RPCs:
void ADefPawnTest::MoveForward(float Val)
{
if (GetNetMode() == ENetMode::NM_DedicatedServer)
{
FVector Dir = GetActorForwardVector();
AddMovementInput(Dir, Val * 200);
}
else if(GetNetMode() == ENetMode::NM_ListenServer)
{
FVector Dir = GetActorForwardVector();
AddMovementInput(Dir, Val * 200);
}
else if (GetNetMode() == ENetMode::NM_Client)
{
ServerMoveForward(Val);
}
}
bool ADefPawnTest::ServerMoveForward_Validate(float Val)
{
return true;
}
void ADefPawnTest::ServerMoveForward_Implementation(float Val)
{
MoveForward(Val);
}