Where To Store Game Manager Style Variables

Hi, I have sort of a question sort of an open-ended discussion. How do you store your variables that manage your game? When I first started game dev, I used Unity and they have a system called a GameManager which basically holds certain values in a level and can manipulate the game in an overarching way. Using UE4 and building multiple levels, I created a GameManager Actor that sits in my world. While it works generally fine, I have run into some issues with it being only accessible within one level unless I use a for each loop to search for it. I’ve also tried attaching some variables that could be part of the Game Manager to the Player Character. Are there any other suggestions as to where I should hold these variables? As a general example for these variables, let’s say there’s three locked doors spread across three different levels. If the player unlocked two of the doors and the game saved those unlocked doors to a save file, where would those unlocked values be written to from the save file? Let me know if I need to clarify this topic as it might be a little confusing.

Game instance:


That’s super helpful! When it comes to initializing variables that reference instances of actors, is the best way to initialize that variable inside the game instance class to set that variable from the actor it is referencing when that actor is spawned in. So to initialize a player variable in the game instance let’s say, should I just cast to the game instance within the Player’s Event begin play, or is there a more efficient way to do that?

Sorry, more specifically, your door example. That would be the save game

As far as variable initialization goes, you can set default values in both the game instance and the save game. If you have many actors of the same type, that would be an array of some sort in the GI or SG.

1 Like

Hi Zapking,
I also come from Unity and making a GameManager actor sounds also very likeable. I’m just new to Unreal and however I’m sure the GameInstance and SaveGame Object are working (and probably more suitable), I was thinking about your problem about not being able to access the GameManager BP. I think it must be possible to attach the GameManager BP to an actor in the scene at BeginPlay. This would solve your issue concerning the GameManager BP in different levels.

But maybe something is going over my head and, as I said, probably the other ways are more confenient.

1 Like