In a third person multiplayer game I open the inventory and from the PlayerController I apply a transformation (translation + rotation) to the follow camera, in order to make it face the controlled pawn. If I apply the transformation to the camera in a server rpc (from the PlayerController) everything works, both on server and on client: both pawns, when opening their inventory, have their camera facing the desired direction.
I am wondering, is it necessary to replicate the follow camera and then call a rpc in order to do this? I would like just to apply locally the transform without asking nothing to the server (and replicate back); but if I do not replicate the follow camera and I apply the transform locally (not server rpc), the camera doesn’ move in client-side.
Is there a way to move the camera both on client and on server without exchancing data on the network, like when displaying some widget on screen?
Yes, as long you got enough data on client to do this. View target actor (which by default is possesed pawn, it does not need ot be pawn) is being asked on every frame (so it works same way as tick) by Camera Manager how it should be viewed, it does that by calling CalcCamera function in actor:
You just set camera state in FMinimalViewInfo argument, the default implmentation of this function searches for camera component in actor and use one first active that is found:
void AActor::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
{
if (bFindCameraComponentWhenViewTarget)
{
// Look for the first active camera component and use that for the view
TInlineComponentArray<UCameraComponent*> Cameras;
GetComponents<UCameraComponent>(/*out*/ Cameras);
for (UCameraComponent* CameraComponent : Cameras)
{
if (CameraComponent->bIsActive)
{
CameraComponent->GetCameraView(DeltaTime, OutResult);
return;
}
}
}
GetActorEyesViewPoint(OutResult.Location, OutResult.Rotation);
}
And yes, this means all camera components in reality are just dummies thta hold camera state while this function apply that state to camera system. So you can easily apply offset here by calling super and then modify camera position. This function is called only on client that renders the game.
Thanks, this is what I was looking for!