Using a bool in GameInstance to spawn an actor

So I am trying to spawn an actor in my battle game mode, depending on whether or not he was in my previous level before the transition. I am using a GameInstance that contains a bool which gets set to true when the actor is spawned in the previous level, however this does not seem to be working for me. I can’t just spawn the actor in without checking if it was spawned previously as I am going to be implementing Stats for each individual fighter. I am totally stuck here as I can’t really think of another way to do this. The BP below is in my battle scene level BP.

Any help is much appreciated!

woops, should be sorted now

I’m setting it inside the actor BP (in this case it’s the ThirdPersonCharacterBP) and the issue is in my level that I want the actor to spawn, it isn’t spawning at all. for testing I have just set the bool to always on, so I’m assuming it’s not being read correctly?

So the actor is just placed in the scene here:

The bool function is being set on eventplay here(in the 3rdpersoncharBP):

I am trying to Spawn a different BP actor in another level here:

and in this new level BP I have the actor spawn BP function set here (titled spawn players):

Screenshot missing

Where are you setting this boolean? Screen shot that too please. Also what exactly is the issue? It doesn’t spawn? The boolean never gets set? The boolean isn’t read properly?

Seems simple enough, so must be a small error somewhere. Unfortunately that means more screen shots. Need to see the entire chain of logic from start to finish. So, how this actor is spawned initially, how this function is called etc. Need the whole flow. Everything seems good from here but is this function actually called? Do you load a new level and spawn again? What exactly is all the back end of this.

Ok this is more complex than you made it out to be initially. Are you loading this from a save game? Because if so there is a whole other area for error right there. Also, gameinstance persists between levels so unless you truly need to “save” like power off the computer and come back to the same spot this is not necessary, game instance will handle persistence between levels. If you are using this bool from a save game then I would need screen shots of how the game is saved and loaded up. That is most likely the error, I see that issue all the time due to improper saving of data.

No I’m not using a save game, I just have the function in the same chain as my savegame function because I needed to use the BeginPlay event, is this bad practice? I don’t think it is what is causing the issue though as for now I have just set the bool I am using to true (Which is stored inside a GameInstance and is set to editable)

Okay a little update, I put a print string on the cast failed node and it seems that it is always failing for some reason

Check the right side world settings panel for the level you are in. Are you using the correct game mode and game instance you are casting to?


Well I’m overriding the game mode, but the cast is the correct one. The same goes for the game instance unless GetGameInstance can be changed somehow?


Okay so it turns out that I am a complete idiot haha, I didn’t realise I had to set the the game instance that I made in the project settings, sorry for troubling you and thanks for your help

No worries, that’s what I figured when game instance doesn’t cast really only 1 reason that happens… not using the right game instance haha anyway glad you figured it out