Setting client controllers from server

Hello,
I’m trying to create my first multiplayer game in UE4 and I need to get aim offset when executing fire action on server. I realize that controllers Pitch rotation isnt replicated (unlike Yaw).

First, I tried AddControllerPitchInput on server using RPC - not working.
From UE4 API:
APawn::AddControllerPitchInput - Add input (affecting Pitch) to the Controller’s ControlRotation, if it is a local PlayerController.
So I assume that I cant set Pitch by this method because it must be local controller ( and it isnt …?.. ).

I tried Controller->SetControlRotation() too - without success.

// set controller pitch input on Server (RPC)
void APlayerCharacter::SetControllerPitchInputOnServer_Implementation(float Value)
{
	//AddControllerPitchInput(Value);
	float newPitch = Controller->GetControlRotation().Pitch + Value;
	Controller->SetControlRotation(FRotator(newPitch, Controller->GetControlRotation().Yaw, Controller->GetControlRotation().Roll));
}

Surely I can create variable in which i will store my pitch rotation and replicate it. Then use it when i will calculate line traces but i dont know if it is right way. I want to do it by getting rotation from clients controller if its possible.

So my question is:
Can I set clients player controllers from server? (I know that Player Controller of each client exists on server but can I set its rotation?)

Hi @adicer, I’m surprised to hear that controller pitch isn’t replicated, but if you need to replicate it manually I usually follow this convention. I’m on my phone so take the following code as pseudocode. I would look for a function called get controller use pitch or something like that.

UFUNCTION(Blueprintcallable)
void SetControllerPitch(float Inpitch) ;

UFUNCTION(Server, Reliable, WithValidation)
void Server_SetControllerPitch(float InPitch);

UFUNCTION()
void Local_SetControllerPitch(float InPitch);

////////  .cpp. ////////
void ABlah::SetControllerPitch(float InPitch)
{
      if(HasAuthority())
      {
        Local_SetControllerPitch(InPitch);
     }
     else
     {
        Local_SetControllerPitch(InPitch);
        Server_SetControllerPitch(InPitch);
     }
}

// Do your validate function 
void ABlah::Server_SetControllerPitch_Implementation(float InPitch)
{
      Local_SetControllerPitch(InFloat);
}

void ABlah::Local_SetControllerPitch(float InFloat)
{
     // Set the appropriate pitch value
}

Hi ZeroParadigm, thanks for answer.
I thought pitch isnt replicated because I was searching for answer to my question before I post it here. And I found some topics where that was said… so I dont know for sure.
Plus it doesnt work for me by default, like yaw do, so I assume its true. :smiley:
So you think that pitch is replicated?

I had similar code as you post here. I made couple of changes following your code. But the problem is in that function with which I’m trying to set that pitch on Controller.

 void ABlah::Local_SetControllerPitch(float InFloat)
 {
      // Set the appropriate pitch value <---- here
 }

I didnt find any other function to set pitch besides AddControllerPitchInput() and SetControlRotation() which doesnt work.

Hey @adicer, you’ve probably already discovered this, as I didn’t receive any notifications of your response and was just rifling through old activity.

The value you are looking for is APawn::RemoteViewPitch

Pawn.h

	/** Replicated so we can see where remote clients are looking. */
	UPROPERTY(replicated)
	uint8 RemoteViewPitch;

It should already be replicated. After reading your post again I remembered that there was something strange about it. So yeah. Use that =]

1 Like