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.