PlayerController, Possess, Replication

Hi,

I try to move the player specifics stuff to my PlayerController, but I have some trouble.

After possessing a pawn, I should be able to add and initialize a widget (through a blueprint call) and set a camera.

First, I tried this:

void AMyPlayerController::Possess(APawn* aPawn)
{
	APlayerController::Possess(aPawn);
	FollowCamera->AttachTo(OwnedShCharacter->GetCameraBoom(), USpringArmComponent::SocketName);
	FollowCamera->bUsePawnControlRotation = false;
	SetViewTarget(this);
    BPAfterPossessEvent();
}

(OwnedShCharacter is initialized at BeginPlayingState(), which is called before APlayerController::Possess() ends.)

But the client will never run the Possess function at all. I also tried BeginPlayingState(). It did not have a valid character reference there.

I could not find a function which would be called on client after the effect of the Possession is replicated - it has to have a valid reference to the character in order to setup things. Is there any function like that?

Thanks for reading,

Elathan

Thanks for the answer!

Unfortunately it will be called before the result of the possessing is replicated to the client - I don’t know why, but GetPawn() still doesn’t give a good result on client side :frowning:

Call it manually. Create PC function like APlayerController::Client_Possess with UFUNCTION(Client) flag and call it inside Possess func on server.

Did you try use OnRep_Pawn?

Thanks, it worked :slight_smile:

However I also had to set bAutoManageActiveCameraTarget to false in the constructor of my PlayerController, cause otherwise SetViewTarget() was called on the local controller after OnRep_Pawn() (with the possessed pawn).

Both the camera and the widget works now on both server and client side.