Again I am new and use a visual scripting program called Adventure Creator. So, now that I am using Unreal it’s just super different and I am trying to get accustomed. In Adventure Creator if you want a global variable, all you have to do is mark it as global. Then it can be used anywhere in the game.
However, for Unreal it seems a lot more complicated. From what I understand there aren’t “Global Variables” I followed this tutorial, but I get stuck at some point. How create global variable?
Could someone explain further? Images and examples are very helpful. I watch Unreal tutorials but they’re sort of fast paced. If anyone knows a more slow paced tutorial for this, let me know. They just go from one thing to another without explaining what anything really means.
Hey there @ImagineTheEnding! So Unreal’s paradigms avoid things like global variables, as they have always been more work to maintain in the long run and worse when scaling games. I personally often recommend creating a new GameInstance and using that to hold your variables that you need to access globally.
Gameinstance are active and maintain data through the entire play session and you can access it from anywhere. This is often where I place saving/loading functionality and data for the session.
Nawrot’s setup over here is probably the closest simple way to keep a global that is maintainable, but it would still suffer from the scale issues if you end up needing more ways to manipulate that variable itself.
Here’s also a video showing how to make a new gameinstance and create variables on it that might make the transition a bit clearer:
Disclaimer: One or more of these links are unaffiliated with Epic Games. Epic Games is not liable for anything that may occur outside of this Unreal Engine domain. Please exercise your best judgment when following links outside of the forums.
Depending on the use case you could create a Replicated Actor placed in the level that contains said variables. Having only the Game mode or Game State govern their values (Set).