Any reliable event / function when PlayerController possesses a pawn?

Hi,

in my PlayerController I want to bind to a delegate of my player character. First I thought to put this in BeginPlay() of the PlayerController but I noticed that in my networking game, the clients will not possess a pawn in their PlayerController when BeginPlay() is called.

Then I chose to override the void OnPossess(APawn* InPawn) function, but this one is actually not called on the ListenServer, I assume because the possession happens before the game starts.

So is there any reliable function call that will be executed in the PlayerController on clients and on the server when the PlayerController owns a Pawn? Or do I need to check it in both functions and make sure I don’t initialize twice?

Thanks in advance

OnRep_Pawn gets called on the Client that possess/unpossess/ the Pawn.

AttachToPawn and DetachFromPawn might be more appropriate to override though called by SetPawn.

2 Likes

Like Garner has said, OnRep_Pawn.

I have created a custom method for my PlayerController though, which essentially combines OnRep_Pawn (only executed on clients) and OnPossess/OnUnpossess (always on server, sometimes clients when it feels like it). I use a HasAuthority check on OnUnpossess because the client doesn’t need to know about it anymore.

1 Like

Thanks for the advice! I will give it a try. Apparently I missed to create this topic as a question so I can’t mark a solution, sorry x.x