Getting Variables from the Game Instance (Global Variables)

ENGINE: Unreal Engine 5.1

I’m trying to set up the Global Variables, to make it easier for me to develop my project, like setting up the animation delay whenever I enter the Play Menu. However even with this setup the Entry Animation is “skipped”, because the variable tied to it somehow is not getting the Variable’s Value from Game Instance. Anyone can fill me in what am I doing wrong or I have to do it the other way?

Hey @GraczCourier!

We’ll probably need more information here. But what I WILL say, is instead of casting down from the game instance (with all of the “Get all widgets of class”), you will want to “Get GameInstance” on the widgets instead. Because the GameInstance WILL exist when the widgets are created, but not necessarily the other way around :slight_smile: . The widgets come after in the load order so it’s possible that you’re not finding anything when you do those searches on the GameInstance.

So basically on “Begin Play” on the widgets, you need to switch the logic to be on the widgets and grab the gameinstance, cast to the game instance (you can Rclick>convert to pure cast for this) and grab the variable you need, then set that on the widgets.

1 Like

Like this?

And what if I have multiple game instances, like this one, focused on the Main Menu for ex.?

Well, there should only be one GameInstance. You can use multiple Game MODES, but stick to one gameInstance, and it should never be destroyed.

And for the context of your question, it won’t matter how many of ANYTHING you have, as long as when grabbing GameInstance, mode, or state, you cast to the correct one. For instance, here, you would cast to the main menu one because you are in the main menu, and the active one is… main menu.

1 Like