Unity

[Unity] Game Creator 2 Variables — Local, Global, Name & List Variables

[Unity] Game Creator 2 Variables — Local, Global, Name & List Variables

Thank you for visiting this site.

This article provides a detailed guide to “Variables”, one of Game Creator 2’s core features.

Variables are data containers for storing game progression and dynamic values. They’re used for everything that changes during gameplay: scores, lives, equipped weapon references, lists of enemies in a scene, and more.

Official documentation: Game Creator 2 Documentation

You can find a complete list of all articles in this series here:

Complete Article List — Game Creator 2 Complete Guide Series Indexen.senkohome.com/gamecreator2-series-index/

What Are Variables?

  • Data containers whose values can be changed dynamically
  • Identified by name (Name) or index (Index)
  • Choice of Local (within scene) or Global (across scenes) scope
  • Can be included in save/load (primitive types only)

Example: Create a Name Variable called score to hold the player’s score. Initial value 0. Add points each time a star is collected, reflect it in the UI, and so on.


Two Types of Variables — Name and List

Name Variables

  • Identified by a unique name
  • Example: score = 47, equippedWeapon = (GameObject)
  • Recommended format for most cases

List Variables

  • An array accessed by zero-based numeric index
  • All elements are held in the same type
  • Example:
    • Index 0: Enemy #3
    • Index 1: Enemy #7
    • Index 2: Enemy #1
    • Index 3: Enemy #4

Which to Use

Name Variables are recommended as a general rule. Use Lists when you have an indeterminate number of targets — for example, selecting a lock-on target from enemies surrounding the player.


Two Scopes — Local and Global

Local Variables

  • Exist only within a specific scene. Become invalid when leaving that scene
  • Attached as a component to a GameObject in the scene
  • Both Name Variables and List Variables are available

Global Variables

  • Shared across the entire project. Can be referenced/modified from any scene
  • Created as a ScriptableObject asset. Runtime values are held by an internal singleton manager
  • Both Name Variables and List Variables are available

ID Conflicts

In either scope, if two variables share the same ID, they will overwrite each other’s values. If you see a conflict message, expand the ID field → click Regenerate to generate a new unique ID.


Value Types

The default types available when setting initial values (modules may add more):

TypeUsageSave Support
NumberNumeric values. Supports both integers and decimals
StringText
Booleantrue / false
Vector 3(x, y, z) vector
ColorRGBA (including HDR)
TextureTexture asset reference
SpriteSprite asset reference
MaterialMaterial asset reference (v2.13.43+)
Animation ClipAnimationClip asset reference (v2.13.43+)
Game ObjectScene GameObject reference

Important: Texture, Sprite, Material, Animation Clip, and GameObject cannot be serialized and thus cannot be saved. Use other types for values you want to persist across play sessions.


Nested Access

A mechanism that lets you traverse to “a variable on the object that a variable points to” with a single key.

Example: Place a target : GameObject in the Player’s Local Name Variables. The target changes dynamically, but every enemy has a health : Number in their Local Name Variables.

→ Simply write the key as target/health with a slash separator, and you can reference the current target’s HP.

This allows you to reach “a dynamic value on a dynamic object” with a single node, without hardcoding reference chains.


Creating Assets/Components

Global Name Variables

  • Right-click in Project → Create > Game Creator > Variables > Name Variables
  • In the generated asset’s inspector, type a variable name and press Enter (or the [+] button)
  • Name, type, and Value (initial value) are editable

Global List Variables

  • Right-click in Project → Create > Game Creator > Variables > List Variables
  • Select the element type and add array elements

Local Name Variables

  • Right-click in Hierarchy → Game Creator > Variables > Name Variables → A new GameObject with a Local Name Variables component is created
  • Or add a Local Name Variables component to any existing GameObject

Local List Variables

  • Right-click in Hierarchy → Create > Game Creator > Variables > List Variables
  • Or add a Local List Variables component to any existing GameObject

Common: Adding Entries

Type a name in the creation field → Enter or [+]. Name, value type, and initial value can be changed later.


Relationship with Save & Load

  • Each variable entry has a Save option that lets you choose whether to include it in saves
  • If Save is OFF: The value is not written during save, and remains at its initial value on load. Useful for “settings that should always start at their initial value after loading”
  • Texture/Sprite/GameObject type variables cannot be saved at all (ignored even if Save is ON)

Properties (Common Abstraction for Accessing Variables)

Many GC2 Instructions/Conditions/Events have dropdowns that dynamically determine field values. This mechanism is called Property.

What Are Properties?

  • Uses polymorphic serialization to dynamically inject options like “constant,” “variable,” “player position,” “child’s position,” etc. into node fields
  • Classes are provided per type: PropertyGet<Type> (get) and PropertySet<Type> (set)
  • Takes an Args struct as argument, which can return context-dependent values using Self (the GameObject that initiated the call) and Target (the target GameObject)

Main Property Classes

  • PropertyGetNumber / PropertySetNumber
  • PropertyGetString / PropertySetString
  • PropertyGetBool / PropertySetBool
  • PropertyGetGameObject / PropertySetGameObject
  • PropertyGetPosition / PropertyGetDirection
  • PropertyGetColor, PropertyGetTexture, PropertyGetSprite, etc.

UI Toolkit required: Custom Editor scripts using Properties must be written with Unity’s UI Toolkit. IMGUI is not supported.

How to Use Properties (C#)

public PropertyGetString myValue = new PropertyGetString();

void Start()
{
    Args args = new Args(this.gameObject);
    string value = this.myValue.Get(args);
    Debug.Log(value);
}

Creating Custom Properties

// A Number property that always returns 42
public class GetNumber42 : PropertyTypeGetNumber
{
    public override double Get(Args args)
    {
        return 42;
    }

    // Short title displayed in Inspector
    public override string String => "42";
}

You can decorate with Title / Category / Description / Keywords / Image / Version / Dependency attributes (same as Instructions/Events). [SerializeField] fields can be added, and you can even nest other Properties inside.


Variables API (Reading/Writing from Scripts)

Local Name Variables

Get the component reference and call directly.

using GameCreator.Runtime.Variables;

LocalNameVariables vars = GetComponent<LocalNameVariables>();

// Get
bool ok = vars.Exists("score");
object value = vars.Get("score");   // Cast to actual type
int score = (int)value;

// Set
vars.Set("score", 100);

// Change notification
System.Action<string> cb = (name) => Debug.Log($"Changed: {name}");
vars.Register(cb);
vars.Unregister(cb);

Local List Variables

LocalListVariables list = GetComponent<LocalListVariables>();

int count = list.Count;

// Push to end
list.Push(someGameObject);

// Clear
list.Clear();

// Move element
list.Move(pickFrom, pickTo);

// Change notification
System.Action<ListVariableRuntime.Change, int> cb = (change, index) =>
    Debug.Log($"{change} at {index}");
list.Register(cb);
list.Unregister(cb);

Global Name Variables

Operate via the singleton manager.

using GameCreator.Runtime.Variables;

GlobalNameVariables asset = ...;   // Asset reference

var mgr = GlobalNameVariablesManager.Instance;
bool ok = mgr.Exists(asset, "score");
object value = mgr.Get(asset, "score");
mgr.Set(asset, "score", 100);

mgr.Register(asset, (name) => Debug.Log(name));
mgr.Unregister(asset, cb);

Global List Variables

var mgr = GlobalListVariablesManager.Instance;

int count = mgr.Count(asset);
mgr.Push(asset, value);
mgr.Set(asset, pick, newValue);
mgr.Insert(asset, pick, content);
mgr.Remove(asset, pick);
mgr.Clear(asset);
mgr.Move(asset, pickA, pickB);

mgr.Register(asset, (change, index) => { ... });
mgr.Unregister(asset, cb);

Common: Pick Classes

IListGetPick / IListSetPick are interfaces that abstract “which index to point to”. Concrete implementations include specific index, first, last, random, and more.


Visual Scripting Reference (All Instructions/Conditions/Events)

Instructions (16)

Category: Variables > ...

InstructionFunctionMain Parameters
Change IDChange the ID of a Local Name/List variable (non-Savable variables only)Name (new ID)
Clear ListDelete all elements from a ListList Variable
Collect CharactersCollect Characters within Min~Max Radius distance from a specified position into a list. Filterable with ConditionsOrigin / Max Radius / Min Radius / Store In / Filter
Collect MarkersSame as above, but targets MarkersOrigin / Max Radius / Min Radius / Store In / Filter
Filter ListEvaluate each List element with Conditions and remove those that return falseList Variable / Filter
Iterator NextIncrement iteration index by +1 (Mode: Loop / Clamp)Index / List Variables / Mode
Iterator PreviousDecrement iteration index by -1 (Mode: Loop / Clamp at 0)Index / List Variables / Mode
Iterator RandomStore a random value from 0 to element count in IndexIndex / List Variables
Loop ListIterate through a Game Object List and execute Actions for each element (sets Target to element each iteration)List Variable / Actions
Move ListMove an element within a List to a different positionList Variable
Remove From ListDelete a specified elementList Variable
Reverse ListReverse the orderList Variable
Shuffle ListRandomize the orderList Variable
Sort List AlphabeticallySort by string (ascending/descending, Ignore Case option)List Variable / Order / Ignore Case
Sort List By DistanceSort by distance from a specified position (nearest/farthest)List Variable / Position / Order
Swap ListSwap two elements in a ListList Variable

Instructions that directly read/write variable values (like Set Number) exist in categories like Math > Arithmetic and Math > Boolean. See the Visual Scripting article for details.

Conditions (1)

ConditionCheckMain Parameters
List Is EmptyReturns true if the specified List Variable is emptyList Variables

To check “whether variable values are equal,” use Compare-type Conditions matching the value type: Math > Arithmetic > Compare Decimal / Compare Integer, Math > Boolean > Compare Boolean, Text > Text Equals, etc.

Events (4)

Subscribe to variable changes from Trigger components.

EventFires When
On Global Name Variable ChangeA Global Name variable is modified
On Global List Variable ChangeA Global List variable is modified
On Local Name Variable ChangeA Local Name variable is modified
On Local List Variable ChangeA Local List variable is modified

These events let you write logic like “update UI when score increases” or “swap icon when target changes” in a loosely coupled manner.


Practical Usage — Configuration Guide by Use Case

Score Management

  1. Create a Global Name Variables asset and add score : Number = 0
  2. In the Trigger’s Instruction when an item is collected, use Increment Number → add +10 to score
  3. On the UI Text side, set the Trigger’s Event to On Global Name Variable Change and use Change Text to redraw

Building an Enemy Lock-On Candidate List

  1. Attach Local List Variables to the Player, created as targets : GameObject type
  2. Use Collect Characters Instruction to collect Characters within 10m of the Player into targets, with Filter set to Tag == "Enemy"
  3. Use Sort List By Distance to sort by distance from the Player
  4. Use Iterator Next / Iterator Random to select, and pass to the Camera Shot’s Change Target

Referencing Equipped Weapon Durability via Nested Access

  1. Place Local Name Variables on the Player with equipped : GameObject (current weapon reference)
  2. Place Local Name Variables on each weapon Prefab with durability : Number
  3. The reference key is equipped/durability (connected with a slash)
  4. On attack, use a Set instruction to apply -1 to equipped/durability

Flags Excluded from Save

For values like “screen settings that should reset to initial values immediately after loading”, use a Global Name Variable with Save set to OFF.

Loose UI Updates Combined with Signals

  • Instead of directly calling UI when a variable changes, fire Emit Signal with "score-changed"
  • The UI side receives with On Receive Signal and updates
  • Multiple UIs (HUD, pause screen) can subscribe to the same signal, making the design highly maintainable

Tips and Caveats

  • Maintain unique IDs: If IDs conflict for savable variables, they’ll be overwritten on load, causing unexpected bugs. Don’t forget to Regenerate
  • List pivots use IListGetPick: When operating on Lists from C#, you don’t pass indices directly as int but go through the Pick abstraction. Use existing Pick implementations (first/last/random/specific index) or create custom Picks
  • Don’t mix types in Nested Access: a/b/c traverses actual variable names at each level, so it cannot resolve if any intermediate level’s type is not GameObject
  • Global variables are convenient across scenes but avoid overuse: Placing values that only make sense within a scene in Global can cause unexpected residual values on scene transition. Keep scopes small
  • Texture/Sprite/GameObject are not saved: If you want to persist them after load, the standard pattern is to hold a recoverable ID (e.g., "weapon_sword_iron") as a String and re-resolve the object from that ID on load
  • Variable change events fire frequently: Connecting Triggers to values that change every frame will hurt performance. If needed, throttle with On Interval or use Signals for explicit notification
  • Using Properties dramatically increases reusability: Simply changing a custom component field from public string foo; to public PropertyGetString foo; lets you supply values from variables, Player references, and more


Summary

This article covered Game Creator 2’s Variables system.

Variables are a simple yet powerful data container system that lets you manage two types — Name Variables and List Variables — across two scopes: Local (within scene) and Global (across scenes).

Features like dynamic reference chains via Nested Access and value retrieval supporting both no-code and code approaches via Properties enable flexible design.

Next, we’ll cover Advanced features (Audio, Signals, Save & Load, Tweening).

Complete Article List — Game Creator 2 Complete Guide Series Indexen.senkohome.com/gamecreator2-series-index/

We hope you’ll continue reading our next article as well.