Has anyone figured out the “right” way to set this up yet?
When APlayerState replicates, the possessed pawn may not have replicated over yet, or the PlayerState property on the pawn indicating possession may not have replicated over yet so you can’t handle it there.
When the Pawn replicates over, the pawn’s PlayerState property may not have replicated over yet so you can’t completely handle it there.
When the Pawn’s PlayerState variable replicates over, the UniqueID on the APlayerState may not have replicated over yet so you can’t completely handle it there.
Once the UniqueID replicates over, you can’t easily handle it because there seems to be no way to get the Pawn at that point (in the OnRep_UniqueId handler) unless you iterate through every Pawn in the game and check if it has a PlayerState pointing to the current one (slow), and the Pawn itself or the Pawns’s PlayerState variable may not have replicated over yet anyway.
Only if you attempt handle it in almost all of those places can it work, but I haven’t figured out how to get the PlayerState’s Pawn in the OnRep_UniqueID without iterating through all Pawns, which may be slow and cause a hitch?
(Edit: the .2 second delay in the official solution above does not look like good practice. I see solutions like that that given in lots of official tutorials on different network things, but it is just wishing away the problem. You don’t see that kind of thing in ShooterGame code, etc.
You need to way until player state, player state’s UniqueId property, the player state’s possessed Pawn property, and the possessed pawn’s PlayerState PlayerState have all been replicated. They can all happen in many different orders, but you can’t fully set things up until they are all there. Maybe that all happens .2 seconds after begin play, but maybe your machine gets choppy and it doesn’t.)