Get gamemode gives me the wrong gamemode

So I got an Actor Component which registers itself to the gamemode. To do so I used the InitializeComponent method. In there I get the Gamemode and I put the Acotor Component in a List in the Gamemode. This works, but after I spawned on the level the list in the Gamemode is empty. I think it is because I use the levels “feature” were you can add multiple levels into one big level. The Actor Components are in a “set dress” level and the Player is spawned in the “main” level, which contains the “set dress” level. What is happening?

Game Mode is recreated when loading a new world. You can even specify a different Game Mode class for each world in the world settings.
If you want to store data for different levels - need to use Game Instance.

So every sublevel in a persistent level got his own gamemode?

No, they have one common Game Mode, but it is created again when you load a new World (Persistence Level) using the Open Level function, or via the “open” command in the console, or “ServerTravel”.

If you don’t change the world, then are you sure you’re trying to get the value after you set it, and not the other way around?

Oh ok thx. Yeah the value is set before we call it. So after some Debugging, we found out that the level needs to be always loaded instead of Blueprint loaded. We think that the Blueprint loader created the Game Mode again, but we are not sure (If someone has a better understanding, I am interesstet in why this happened). Still thx :smiley:
grafik

If you are trying to get a value by BeginPlay, and set it also by BeginPlay(InitializeComponent) - then the sequence of their calls is difficult to predict, and you definitely shouldn’t rely on it.

And if you get a value by BeginPlay of an already loaded level, and then load a level in which this value is set by BeginPlay, then you will definitely get something different from what you set.