You can make functions in function library, and store that “Global” variable in game mode or game instance.
First make bp game mode and your variable inside of it:
- variable declaration in BP_Game_Mode (create this blueprint based on game mode class, add variable)
Second, make Blueprint Function Library. And make those 3 functions inside:
-
Get Game mode (this is mainly to make SINGLE point/code in case you want to store those global variables elsewhere, also single point to add logging or error checks) this is PURE function (tick that pure checkbox)
-
PURE function again, that gets your variable. (cast to is already done in above function Get Game Mode)
-
Set your variable NOT pure.
Third, how to use it or THE RESULT. This works in ANY blueprint, just like variable that is global.
ps.
Quite Important: SET that variable only from SINGLE place, and everybody else reads it only.
If you start setting this variable from different blueprints you may get weird results, because you cannot be sure which place set it last. It is very easy to mess things up, unless you only care about most recent value.