PlayerState is pending kill in event OnLogout of GameMode

Due to the GameMode refactoring in UE 4.14, if you are using GameMode (Not GameModeBase), the playerstate of the exiting controller is being deactivated (destroyed) on the end of the method AddInactivePlayer (GameMode.cpp line 667). As the Super::Logout() is being called after AddInactivePlayer, the playerstate is pending kill in the Blueprint event OnLogout.
As a fix suggestion: Maybe it makes more sense to move the Super::Logout() to the start of the method instead to the end?

Probably more stuff got broken by this, since the pending kill playerstate will be used in the GameSession->NotifyLogout(PC) (GameModeBase.cpp line 940) resulting in UnregisterPlayer is not happening properly.

If you want to reproduce the bug:

  1. make a new project with a own playerstate and gamemode blueprint class.
  2. Add a variable there.
  3. add the Event OnLogout to the gamemode.
  4. In the Event, cast the exiting controller to playercontroller and try to access the playerstate variable there.
  5. Start the game with at least 2 players
  6. Disconnect with the client player and see the pending kill errors in OnLogout.

By the way, in 4.13, the playerstate was accessable in OnLogout. I compared the code and it confirmed, that this bug spawned in 4.14 (There is no AddInactivePlayer call in Logoug of GameMode.cpp).

Hey NilsO,

I’ve attempted to reproduce the issue on my end, but I’m not seeing the same results.

Could you clarify step 2 of your repro? What class are you adding a variable to and which type of variable are you adding?

Also, do you have a screenshot of the blueprint setup that you’re using to get the player state and access the variable OnLogout?

Hey Sean,

okay, first here are the blueprint screenshots of our project:

OnLogout of our GameMode:

Unregister player method:

By the way, make sure the parent game mode class is:

116090-gamemodeparentclass.png

It is kinda a “last man standing” game mode, i wan’t to actually end the game, if the last player of the hunter or witch team left the game by disconnecting. I store the information about the team in the player state, which should be the right place. All these mechanics are not working anymore since 4.14 due to the described changes to GameMode.
I could implement a workaround where i fill arrays (one array for each team) into the GameState with the appropiate player controller. But honestly, for me it really looks like, that such a behaviour is not intended. And well, it would be double care, making it more susceptible for bugs and generally undynamic.

I Hope it helps!

By the way! Funny, i just found a small flaw in the blueprint code, the mechanic itself is broken because of this:

116103-isendround.png

After adding the NOT node, it is working again (i refactored it some time ago, and this bug was left facepalm).

BUT even if the mechanic works again now, the error output still remains:
Error Blueprint Runtime Error: Attempted to access B_PlayerState_C_1 via property K2Node_DynamicCast_AsB_Player_State, but B_PlayerState_C_1 is pending kill from function: ‘UnregisterPlayer’ from node: Branch in graph: UnregisterPlayer in object: B_GameMode with description: Attempted to access B_PlayerState_C_1 via property K2Node_DynamicCast_AsB_Player_State, but B_PlayerState_C_1 is pending kill

Thanks for the additional information. I’m still not seeing the pending kill error on my end when I disconnect from the server. Could you create a simplified test project that showcases the issue? I’ll provide you with a base mutliplayer setup to save you some time, and you can make the necessary modifications, as it’s possible that I’m overlooking something and that’ll help me get a better idea of what it is that I’m missing. link text

Thanks!

Hey Sean,
well, first said: I further have found out, that the variables in the player state goes frag in the Logout method. It leads to the fact, that the mechanics for my game are still broken and the outcome is totally different as intended.

So i got your project and have reproduced the pending kill error, here is it:
link text

As a short description (what i actually changed):

  1. The EngineAssociation in the AH484873.uproject was set to 4.13, where the pending kill error is not happening (i changed it to 4.14).
  2. For some reason, the client always spawned as spectator (the “Start Players as Spectators” is not set), so i added a OnPostLogin where the actually Character_BP is being spawned and possessed by the player.
  3. For the proper disconnection test, i was a little bit lazy and instead of Jumping with Space, you now will disconnect with Space and return to menu.
  4. I’ve added a custom GamePlayerState_BP with a SomeInteger variable.
  5. With the left mouse button the according player can increase the SomeInteger by one per click.
  6. When the client player leaves, the Event OnLogout happens in Game_BP, i just print out the SomeInteger of the leaving player.

After hitting the Space key with the client, this error happens:
PIE:Error: Error Blueprint Runtime Error: Attempted to access GamePlayerState_BP_C_1 via property K2Node_DynamicCast_AsGame_Player_State_BP

And the printed SomeInteger of the leaving player state is always “0”, which should be at least “5” (due to the default value i set).

Alright, i hope it helps!

After additional testing, I’ve confirmed that the issue is occurring in 4.14. However, after testing in our main internal branch, I am not seeing the error occur, leading me to believe that this has been resolved for 4.15. Upon release, please feel free to respond to this thread if you are still seeing the same issue in 4.15.

Thanks for your report and for providing all of the information.

Edit:

In the meantime, you could try moving the Super::Logout call in GameMode.cpp’s Logout function to the top of the function. When I did this, it seemed to remove the error. Let me know if that helps resolve the error on your end as well.

Have a great day