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:
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)
Editor: I try to run RestartPlayer (Function of GameMode) from Player Controller blueprint.
Editor: I try to run RestartPlayer (Function of GameMode) from Character blueprint.
Editor: I try create custom event inside MyGameMode which run RestartPlayer but cannot run this custom event inside MyGameMode also.
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.
VS: in Entire Solution put breakpoints on setting “AuthorityGameMode” but do not catch anything.
VS: try to debug GetGameMode() inside GameplayStatics.cpp:
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
.
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.
I try to run RestartPlayer from GameMode so cannot move my code to GameInstance or PlayerController.
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.
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)
I search information about it in google, but can’t find not even ONE !!!
UE 4.24.3
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.
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
Next observation: Into MyGameMode I override “Event Destroyed” - and in random time when I move players and do nothing else - sudenly MyGameMode Destroyed No player dying, no fire, no AI interaction, only move
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”.
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.