‘Global’ Variables in Unreal – 2 methods

Here are two methods to get variables to be global in Unreal.

First Method using a Game Instance — advantage = works between levels
Second Method using a Material Parameter Collection — advantage = Quicker to set up

1. Game Instance Method

Make a Blueprint of type GameInstance. (NOT GAME MODE)

You need to set your level to use this game instance in Project Settings /Maps and Modes/ Game Instance/ Game Instance Class to <YourGameInstance> (NOT GAME MODE)

Then open the game instance up and add some variables.

To access these variables to either get or set them, in another blueprint you need to Get Game Instance and then Cast To <YourGameInstanceName> (mine is called WeatherComntrol.)

Pulling a wire from the Blue output dot you should see under Variables/Default <Your VariableNames> that you can either get or set. Here I’m getting a float and a interger

Getting a float and an integer

2. Material Parameter Collection

Typically, Material Parameter Collections serve the purpose of sharing values among materials. For instance, let’s consider a scenario where multiple objects within a level should turn red under a specific condition, for example, when the user hits the space bar. By utilising the same Material Param Collection across different materials, any change in colour would affect all the materials using it, resulting in a simultaneous colour change across those materials. We can use the Material Parameter Collection to store and retrieve multiple scalars and vectors, and we can use these values in other places besides materials.

To do it, first R-click in the content browser and make a material parameter collection and give it some values.

A material parameter collection with a Scalar and a Vector, but they can hold as many as you like

Then in any blueprint, you can set or get the named parameter. You can use it to change values in materials or anything else or vice versa.

A material parameter collection at work in an actor blueprint. You just need to know the Mat Param Collection name and the name of the Parameter you want, in this case its a float called WindDirection

About Gibson/Martelli

British electronic arts duo Gibson/Martelli make live simulations using performance capture, computer generated models and an array of technologies including Virtual Reality. Artworks of infinite duration are built within game engines where surround sound heightens the sense of immersion. They playfully address the position of the self in relation to technology, examining ideas of player, performer and visitor -intertwining familiar tropes of video games and art traditions of figure & landscape. www.GibsonMartelli.com