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.

1 Like

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

Ok so something similar to “game management” would be “audio management”. I right now have a back ground music manager system where it, as the name implies, manages the background music. It has its own logic within it. But referencing it can be a little difficult when working with multiple levels. Would I use the game instance object for this as well, or is there a better system that I can use, or is having an object out in the world that I created to manage the music the best option?

It really depends how you’re switching levels.

If you are using level streaming, then the BP managing the music can just sit in the persistent level.

If you’re using ‘open level’, then the music control needs to be in the game instance.

you can use the GameMode for such things, too.

Create all functions and Variables to deal with Game Rules there and just feed it, via GetGameMode or by let itself load a savegame where setups are stored.

Keep in Mind:
GameMode, is for Game Rules and Rule Execution. in Multiplayer (=MP) is can only be “asked” to do Stuff, via the Authority (=Server). Clients (=Remote) don´t have access to GameMode Functions and Variables.
So… things like playing Music, spawning stuff and keep track of Level Variables (like Day/Night time) belong to this Class.

The GameMode Class gets destroyed after leaving a Level and spawned again for the new one.

The GameInstance (=GI) instead, is Game-Static. It “spawnes” on Gamestart and is the first created Object after launching the Game.exe.
A GI is never destroyed or unloaded, before Quitting the whole Game…
So… every Variable in there, persists over the full Time the Game is opened.
BUT - it is not a secure place for Game Rule Variables, since it can easily be called in via GetGameInstance and Casted… Even in MP… And even by the Remotes…

So… stay with the GameMode for really important Level Setups.
STore the Settings of each level in a File and let the GameMode load that by Level Name on Level Begin.

1 Like