GameMode in SinglePlayer randomly stop existing


I meet again problem with GameMode. I spent few days and can’t figure it out why this happen.

Blueprint node GetGameMode return “none” after randomly time of playing.

What I tested:

  1. Editor: GetGameMode off to IsValid sometimes return:
    a. Not Valid (GameMode is None)
    b. Is Valid (Function inside GameMode is never run - Error inform that MyGameMode is Pending Kill)
  2. Editor: I try to run RestartPlayer (Function of GameMode) from Player Controller blueprint.
  3. Editor: I try to run RestartPlayer (Function of GameMode) from Character blueprint.
  4. Editor: I try create custom event inside MyGameMode which run RestartPlayer but cannot run this custom event inside MyGameMode also.
  5. Editor: I try “Get All Actors of Class” which search MyGameMode - this work same as “Get Game Mode” node, after random time “Get All Actors of Class” not find MyGameMode Instance.
  6. VS: in Entire Solution put breakpoints on setting “AuthorityGameMode” but do not catch anything.
  7. VS: try to debug GetGameMode() inside GameplayStatics.cpp:
  8. Editor: GetGameMode check by IsValid and when “Is Not Valid” try to run GetGameMode check again after 0.1 second - never work again - simply GameMode Instance disappear :frowning:


AGameModeBase* UGameplayStatics::GetGameMode(const UObject* WorldContextObject)
	UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
	return World ? World->GetAuthGameMode() : NULL;

World in first line is always well.
In second line GetAuthGameMode() return nullptr.

Other information.

  1. I try to run RestartPlayer from GameMode so cannot move my code to GameInstance or PlayerController.
  2. My game is now Single Player but split screen with two Player Controllers and Two Pawns. But soon I want to make multiplayer with sessions.
  3. Two month ago I met same problem with GameMode with Multiplayer Game which I programmed. I overpass it to move my co from GameMode to GameInstance (which is not good solution)
  4. I search information about it in google, but can’t find not even ONE !!!
  5. UE 4.24.3
  6. Very strange is that sometimes after first player death when I need to GetGameMode is failed, sometimes after 30 player deaths GetGameMode failed - for me is randomly.
  7. When I try to run RestartPlayer function from not valid return of GetGameMode I have error:


LogScript: Warning: Attempted to access MyGameMode_C_0 via property CallFunc_GetGameMode_ReturnValue, but MyGameMode_C_0 is pending kill
    MyCharacter_C /Game/GG/Maps/UEDPIE_0_PlayMap.PlayMap:PersistentLevel.MyCharacter_C_1
    Function /Game/GG/Play/MyCharacter.MyCharacter_C:ExecuteUbergraph_MyCharacter:00CC
PIE: Error: Blueprint Runtime Error: "Attempted to access MyGameMode_C_0 via property CallFunc_GetGameMode_ReturnValue, but MyGameMode_C_0 is pending kill". Blueprint:  MyCharacter Function:  Execute Ubergraph My Character Graph:  EventGraph Node:  Restart Player

If this is not Engine BUG, where can I look for my mistakes ?

Do you ever change your level (like by using the open Mylevel console command) or restart/reload your level (Maybe by using the Restart Game Blueprint Node)? You might want to search your code for and Blueprints for anything like that. You could also search for all the places you call Destroy Actor in your code, and make sure it’s never being used to Destroy the GameMode.

No problemo i fixed formatting for oyu, use code formating for logs, also there seem ot be bug in anwserhub before point formating oyu need to have something before it for code formating to work so i placed dots

Hm, message is formatted very bad, without new lines :frowning:
How to edit my post ?

I don’t know how to edit badly formatted text in this post. So, here is well formatted:

nrossol: I do not use open level. Destroy Actor concern only old Pawn after RestartPlayer. Restart Game also I do not use.

Thanks !

has anyone ever encountered such a problem? I have to deal with it already in the second project on 4.24. Maybe it’s Engine Bug ?

Maybe someone know how to create new GameMode when my stop existing ? This can be work around this problem.

Next observation: Into MyGameMode I override “Event Destroyed” - and in random time when I move players and do nothing else - sudenly MyGameMode Destroyed :slight_smile: No player dying, no fire, no AI interaction, only move :slight_smile:


I probably found a cause.

MyGameMode has ProjectileMovement Component. I do not know how I put it there ;-).

I probably added it by accident.

When I remove it, never happen MyGameMode Destroy again :slight_smile: :slight_smile: :slight_smile:

Thank you for your help!

I have seen similar bugs to this when I accidentally call functions on an Actor that has already had “Destroy Actor” called on it. I also got this when I accidentally tried to destroy a Character twice (like when a character is killed by 2 different missiles on the exact same tick).

When your Character is killed, do you call Destroy Actor on the Character? It is very important that once you call “Destroy Actor” on an Actor that you don’t run anymore code on it (this can be challenging to ensure due to things like Delay nodes, multicast events, etc.). “Destroy Actor” should usually be the very last thing you do. I suspect the error might be that GameMode is not actually deleted, but rather that the Character is not allowed to access GameMode anymore because the Character is being deleted.

To test this: Right before you call “GetGameMode” you should check “isValid” on “self”.

If “self” is not valid, than that is actually the root of the problem.

Thank you very much! I will secure my code!

Thank you! In the process of loading actors I forgot to connect a single actor ref to a destroy node and it was deleting the game mode! One second after reading your post it hit me, I must be deleting it during the loading process.