[Repro] OnRep_Pawn Only Fires When Possessing A Newly Spawned Object

After months of trying to work this one out, I finally narrowed it down - though I can’t figure out why it’s occurring. Zak Middleton managed to fix the Possession issue in 4.8, but it appears that wasn’t the only issue occuring.

OnRep_Pawn only fires on clients if the object you’re possessing has just been Spawned by the Server. It does NOT get called if the Pawn you’re trying to possess already exists in the world (both Client and Server that is).

Here’s a video of the issue occurring in my game. The vehicles are just Pawns (not Characters). When I spawn in as a a Character class object, OnRep_Pawn get’s fired. If I try to possess one of the Vehicles on the Client, OnRep_Pawn never get’s called. This is because they already exist on the Client and server.

WHen I first spawn in as a vehicle, OnRep_Pawn also get’s called. It doesn’t get called if I subsequently try to re-possess the vehicle after hopping out of it, because it wasn’t just spawned by the server. The Debug Messages should indicate this!

This is the code I'm using in my Custom Player Controller to do this:
void ABZGame_PlayerController::OnRep_Pawn()
{
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("OnRep_Pawn Called!"));

	Super::OnRep_Pawn();
}

Did this ever get bug tracked cause it is still happening =)

Actually I was able to figure out what is going on.

There are 2 client functions that can ‘SetPawn’, “OnRep_Pawn” & “ClientRestart_Implementation”. Epic states inside of the code that they can’t guarantee which will set the pawn first so whoever is call first will prevent the second notify from running.

If OnRep_Pawn is not running, its because “ClientRestart_Implementation” or plainly “ClientRestart()” instead and it can be vice versa in some scenarios.

Hope that helps others out.

I finally figured that the best place to run my code was inside SetPawn(), which runs both client and Server side.

I was hittin a wierd issue where the pawn would replicate initially as null, then would be set - but since you can’t garauntee order, it’s just easier to ensure the code handles it that way.

So yeah, overall my use for it works fine now!