While originally attempting to fix a problem related to infinitely driving cars I started adapting the GTA Style Vehicle Interaction project (GTA Style Vehicle Interaction - Project File Included - Community & Industry Discussion - Unreal Engine Forums) and I ended up finding out that Possessing caused some issues.
This is a problem that occurs both in C++ as well as Blueprints.
Basically, possessing a pawn after spawning it results in a weird/invalid game state.
In case of the GTA project:
- The vehicle is still sort of possessed and keeps processing the last input it received before Possess was called on the new pawn. However, since it is not really possessed, further input (such as releasing throttle) is never processed. As a result, itâll keep on driving forever.
- The player camera moves to the spawned pawnâs camera as if itâs being possessed, however it does not process any input.
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
- When the previous pawn is destroyed before calling Possess() on the new pawn, everything works fine. This is also most likely the only reason why the RestartPlayer() function is working at the moment; it seems that by default it is only called after a playerâs pawn has been destroyed.
- When adding a delay between spawning and calling Possess() on the new pawn, everything works fine. This delay probably allows for the spawned pawn to replicate completely.
If you want to look at the GTA project (grab it here: Dropbox - GTAVehicleSetup.7z - Simplify your life), 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.
References
Someone who had the same problem:
GTA Vehicle Interaction Project: