After several days of trying to implement what should be a fairly simple feature and a few (admittedly vague) threads/hub-posts left unanswered, I’d like to highlight a few issues with Multiplayer Possession of Pawns in 4.6.1, and hopefully get the issue solved before 4.7 is released.
I’m trying to implement a very simple system that allows a Player to take control of Vehicles using their ‘Character’ pawn. In Single-Player this is incredibly simple and straightforward, but Multiplayer Pawn possession is riddled with layers of complexity that I’ve been scratching my head over for almost a week, and after trying tens of different approaches in both C++ and blueprint, following documentation and example content, I am still left with a broken system that yields different results everytime I run it. For the simplest demonstration of the issue, I recommend downloading and testing Jacky & Omar’s GTA-Style Vehicle Possession system in Multiplayer. It’s in Blueprint, but the issue is present in both C++ and BP’s. It seems I am not alone, as they too are struggling to get Pawn Possession over a network working reliably; and Omar has an Answerhub post as well that Adam Davis is currently looking into (for which I am eternally grateful!). I have since tested Omar’s project in 4.7 Preview 4, and the issue is actually made worse here, because the Delay he introduced doesn’t fix the Replication bug and as such you’re still left floating with no control over your newly spawned Character (well, cube in this case), regardless of what workaround you try.
So here’s the general flow of what is supposed to happen in my own system:
- Player spawns in game at the start as EITHER a vehicle or a Character class (GameMode decides). Vehicle is just a sub-class of the default ‘Pawn’ class.
- Characters can possess vehicles simply by walking up to them, and a Hit event on the Capsule component will talk to the server, telling the clients player controller to ‘possess’ the vehicle.
- The Character left behind is destroyed instantly, not before having it’s collision disabled and meshes hidden in case the destroy process takes longer than anticipated.
- The Player can do whatever vehicular-based activity they please and then ‘Hop Out’ of the craft.
- When the Client asks to exit the craft, the server spawns a new Character for them and tells the controller to possess that instead. The vehicle is then empty for other Players to come along and use.
- THIS is where the problem occurs, the spawned Character is possessed, but I never get control for it on the Client, and it sits hovering in the air.
There is a second issue in all of this, sometimes, my Player Controller does not successfully possess the Vehicle either, and I am once again left hanging in mid-air with no control. I experimented a little and found that if the character was destroyed before the possession completed (or rather, replicated), then it would fail completely. I got around it for now by setting the Lifespan of the character instead and hiding all it’s meshes and collisions. That seems like a lengthy and unreliable workaround for something that should just work all the time, especially over a localhost connection. In a laggy network game, that order of operations is going to cause big ol’ problems…
–
I have been rummaging through answerhub and the forums for a few days looking for an explanation, and even religiously followed this tutorial in 4.6.1 and tried to adapt it for this, which still didn’t work. I can’t pass ANY control information to the Character once it’s been possessed, and I float in the air in limbo, on both the server and client.
My game pivots on the ability to hop into and out of loads of different vehicles dynamically across a network, no different to UT3, GTA or similar. Unfortunately UT4 hasn’t implemented any vehicle code yet so there’s no example content to look at for this, and the fruit of my searching has been finding this post on answerhub, which demonstrates an issue with the way it’s handled by the Engine itself, not with my methods of coding, of which I’ve tried several different approaches. I feel like I’ve tried everything; spawning the vehicles dynamically at the start of the game, asking the GameMode to spawn the character and possess through there, even handling all input and possession through the player controller. Literally everything… Now I really think it’s just that there is an engine-level bug at the moment stopping clients being able to change the pawn they’re possessing reliably.
Possible Related Items:
I posted a similar thread the other day here, which highlights OnRep_Pawn not being called reliably, but again by some magical luck of the draw.
I tried to implement the system in Blueprint (again, several iterations and attempts). It’s worth noting that calling either ‘Possess’ or ‘Unpossess’ in either blueprint OR code on a client caused me an instant Access Violation crash too, with no callstack or explanation as to what the AV was. I’m betting something to do with the Pawn.
–
Currently my project is stalled due to this bug, I can’t go back to an earlier engine version and 4.7 makes the issue even worse. I know I know, I’m whining a bit now, but I’d really like to see this issue resolved before 4.7 hits, or I’ll end up having to wait a long old time before somebody comes across the problem and makes the fix, or even until UT4 starts adding vehicles and the dev team realises there’s a weird issue with it there.
Thanks folks!