Spawning a Pawn and Possess()'ing it doesn't function properly in MP with replication.
While originally attempting to fix a problem related to infinitely driving cars I started adapting the GTA Style Vehicle Interaction project (https://forums.unrealengine.com/showthread.php?44214-GTA-Style-Vehicle-Interaction-Project-File-Included) and I ended up finding out that Possessing caused some issues.
Basically, possessing a pawn after spawning it results in a weird/invalid game state.
I suspect this indicates a bug in pawn and controller replication, or rather, the order in which it replicates.
There are at least 2 workarounds that kind of work that you could use in the meantime but these aren't workarounds for nothing :P
If you want to look at the GTA project (grab it here: https://www.dropbox.com/s/gqka9hgpwc70x4w/GTAVehicleSetup.7z?dl=0), the asset of interest is Blueprint'/Game/Sedan/Sedan.Sedan', Event Graph and then the node sequence attached to the 'EnterVehicle' Input Action. If an even smaller sample is needed I may be able to provide that later this week, or otherwise maybe next week.
GTA Vehicle Interaction Project:
Ok, I finally got a chance to look at this in depth. Thank you for providing the test project, it was very helpful!
The good news is that everything can be made workable in the current release. I just tested with the latest 4.7 code, but I believe this should work in 4.6 as well.
The root of the problem is that you are calling Possess() on the client. This is not supposed to happen, although it's our fault that we don't message this or restrict this call. We will fix this in a future release (too late for 4.7 though). For now just make sure that you spawn Pawns on the server, and Possess() them there as well. This also explains why some people were asking why OnRep_Pawn() was not occurring on clients: they had already possessed it on clients, so they didn't get the network notification because that only happens when the value changes.
The fact that you immediately destroy the character while there is a pending RPC or replication is also not good. If you really need to destroy the character, insert a delay. Typically in this scenario we suggest hiding the actor, disabling collision, and disabling ticking. Then when you exit the vehicle, place the actor where you need it, and re-enable all those things.
There is one engine bug that will be fixed for 4.8, but you can work around it, in blueprints or in code. The issue here is spawning an actor and then immediately calling Possess(). They can get to the client in the wrong order and the possession can fail. If you don't spawn the pawn (because you hid it instead of destroying it), this isn't an issue.
To work around this, in blueprints, you just need to insert a short delay between calling SpawnActor and then possessing it on the server (you already had this, this is just for general information).
The code fix is simple, in APlayerController::ClientRestart_Implementation():
Here is an overall breakdown of the necessary Blueprint changes in your project:
New character (possess on the server only, and don't destroy the pawn):
New sedan. Basically just only do stuff on the server. I left the SpawnActor node, but you could remove it if you don't destroy the pawn, and then you can drop the yellow circled node which is the workaround for the engine code issue:
I hope this clarifies things, and thanks for bearing with us as we worked this out!
answered Feb 13 '15 at 05:12 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here