Question when switching levels

Hey, i noticed if you have a script running and when you switch to another level the script will be cut off and the script will no longer run. I think when i open a new level i destroy everything except the game instance i might be wrong there

i was wondering if there is anyway to counter that?

bc i have a main menu and a button when i press the button it loads me to a new level but i still want the script to run or atleast check if the button was pressed when i load the new level.


What is the problem? You have a button that loads a level when it is pressed, but you need to check if it was pressed before loading the level? If you connect the Open Level node to the button’s “On Clicked” event, this should work for you, right?

yes, load a game destroy all except the gamestate, everything you have created is contained within that level, if you want to keep code or actors you have the streaming system

1 Like

Have your button set a flag in the GameInstance, before loading the level, that you can check when your level loads. You then need to add code to your “BeginPlay” in the World Blueprint (or have a custom actor in your loaded level that contains the logic) to check the flag you set prior to the level change.

1 Like

Yeah the problems is that i want to load a save but it cant do that since it will cut off when i switch a level. so i was wondering if there is a way to counter that

will look more into that thanks

probably a dumb question but how do i set a flag. and at the begin play on the other level i can just check if that button was pressed right?

Add a variable to your Game Instance class (for example a Boolean value) and set it’s value accordingly. For example - in my current project I detect which play pressed fire, I then set an integer value to 0 or 1 to tell the next map which player should be created.

1 Like

yeah i kinda get what you mean. is it like this?

EDIT: i did this instead



That’s the basic idea - but no need for the custom event. Add your variable to the GameInstance class and make it public. Then your “Set Save 1” can be called in the Event Graph where you call “Custom Event”.

1 Like