Do UE4 blueprints have any concepts like 'global' variables?

I want to make some basic data in my level blueprint available to all my AI characters,

how would I do this?

Blueprint Interfaces!

Yes, at the end of a variable there is a button to make the variable global, if you click this your variable / function / whatever will be publicly available to other Blueprints.

well no, because you still need a reference to an instance to be able to call an interface. right? so what do I do if there’s data in the level blueprint I want to access in my character?

where is this button? I can’t see anything to make it global. Do you just mean editable and / or public? that’s not the same thing as a global. I’m talking about replicating something like a singleton level global.

also if I CAN do this with interfaces, can you please explain how? thanks!

As far as i know, there is not Global variable for blueprints. Also accessing the LevelBlueprint in other Classes is only possible with EventDispatchers or BlueprintInterfaces.

But what you could do is using the GameInstance Class. Just make a new Blueprint deriving from Game Instance. Create your variables inside. You can get it everywhere with the node “GetGameInstance” and cast it to your specific custom class. This should be global and also live over levelchanges.

http://puu.sh/dkHcC/6cc185e22e.jpg

Does this solve your problem? If not, feel free to ask me.

The problem with level blueprints is that other blueprints have no knowledge or capability of compiling / communicating with them until runtime / Begin Play. At least that is my impression of the systems so far. It is very common to use for example Event Dispatchers to connect the Level Blueprint to other blueprints.

To get started on helping you with this, it would help greatly if you could tell us what kind of data there is which you want to share with the AI.

A suggestion, for starters, is to get perhaps the AI Controller or GameMode on Begin Play from the Level Blueprint. Then store the values that you need access to.

Thank you for this, very helpful! I’ve ended up actually using interfaces and spawning my agents in the level blueprint, then with that instance I send through references to the data I need using the interface.

But how do you set the default value for these global variables if they are based on another variable? What if you have “purple inventory slots” and “yellow inventory slots” and I want a global variable that is the sum of those 2 together at gamestart? That is not possible from a BluePrint from GameInstance. There is no EventBeginPlay and no constructor and no way to provide any sanity checks.

I know that this question is kinda old, but…
There is a simple solution with blueprint pure const function library. Just create BPLibrary with functions like this

http://puu.sh/mGSzE/d9697ca448.png://

No casting or other extra nodes needed in actual BP.
You also will able to load this value from config with Rama’s Victory BP plugin i guess or just custom c++ bp library if you feel it’s needed.

This is a pretty good solution really - don’t need to place anything, works in all game modes and works in the editor. Thanks