Ownership/Role issue on possession switch (player->AI) in networked game
My team and I have encountered a very specific bug that has to do with switching pawn possession with a playercontroller and an AIcontroller in a networked game.
During a networked game, we allow a player to be controlling pawn A, and an AI to be controlling pawn B. During gameplay, the player may switch over from possessing pawn A to possessing pawn B. At this point, the AIController that was possessing pawn B will now be possessing pawn A. When testing this during regular single-process PIE as well as non-single process PIE, a bug occurs on Client >1. What I mean by this is that the bug does not manifest on the listen server client, nor does it manifest on Client 1, but Client 2 and Client 3 (which is as far as we have tested this) will see the bug. The normal behavior is that the player will correctly possess the once-AI, and the AI will possess the once-player, and the AI will be moving around according to their defined behavior. The bugged behavior is that the AI will not be moving on the bugged client. All of the other clients will see the AI moving around correctly. If the player were to switch back to their original pawn (which is now the bugged AI pawn) then they would teleport to the correct location according to the server.
In a clean project, have a level with 4 or more default character pawns. Give the default AIcontroller to one of the pawns, but make sure it moves around in some looping way so you can observe the issue. Write some simple possession-switching logic on a keypress, where the controller that pressed the key will swap possession with the AIcontroller. Then Play in Editor with 3 or more clients, just make sure Clients 2+ are controlling a pawn so that you can test this. As Server or Client 1, try swapping to the AI. You'll notice that it works correctly and the AI is now controlling the pawn that the client was controlling, and it's moving around correctly. Then try the same thing with Client 2, and you will notice that the playercontroller is able to move the newly possessed pawn, but the AI will not be moving in its newly possessed pawn. The other clients will observe everything as normal, just the client that initiated the swap will not.
Some things to note:
If you print the Local Role of the pawns, you will notice that when this bug occurs the pawn that the AI switched to is still printing "AutonomousProxy" when it should be printing "SimulatedProxy".
We've been looking through the engine code to try to figure out a workaround. However since it's reproducible in a clean project, we thought it'd be a good idea to post.
asked Jan 24 '19 at 11:16 PM in Bug Reports
Follow this question
Once you sign in you will be able to subscribe for any updates here