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:
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):
| Type | Usage | Save Support |
|---|---|---|
| Number | Numeric values. Supports both integers and decimals | ○ |
| String | Text | ○ |
| Boolean | true / false | ○ |
| Vector 3 | (x, y, z) vector | ○ |
| Color | RGBA (including HDR) | ○ |
| Texture | Texture asset reference | ✕ |
| Sprite | Sprite asset reference | ✕ |
| Material | Material asset reference (v2.13.43+) | ✕ |
| Animation Clip | AnimationClip asset reference (v2.13.43+) | ✕ |
| Game Object | Scene 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.
C# Programming Through Unity 3D Game DevelopmentView on Amazon →
Zero to Start! Unity Game Development — Your First TextbookView on Amazon →
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 aLocal Name Variablescomponent is created - Or add a
Local Name Variablescomponent to any existing GameObject
Local List Variables
- Right-click in Hierarchy →
Create > Game Creator > Variables > List Variables - Or add a
Local List Variablescomponent 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) andPropertySet<Type>(set) - Takes an
Argsstruct as argument, which can return context-dependent values usingSelf(the GameObject that initiated the call) andTarget(the target GameObject)
Main Property Classes
PropertyGetNumber/PropertySetNumberPropertyGetString/PropertySetStringPropertyGetBool/PropertySetBoolPropertyGetGameObject/PropertySetGameObjectPropertyGetPosition/PropertyGetDirectionPropertyGetColor,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 > ...
| Instruction | Function | Main Parameters |
|---|---|---|
| Change ID | Change the ID of a Local Name/List variable (non-Savable variables only) | Name (new ID) |
| Clear List | Delete all elements from a List | List Variable |
| Collect Characters | Collect Characters within Min~Max Radius distance from a specified position into a list. Filterable with Conditions | Origin / Max Radius / Min Radius / Store In / Filter |
| Collect Markers | Same as above, but targets Markers | Origin / Max Radius / Min Radius / Store In / Filter |
| Filter List | Evaluate each List element with Conditions and remove those that return false | List Variable / Filter |
| Iterator Next | Increment iteration index by +1 (Mode: Loop / Clamp) | Index / List Variables / Mode |
| Iterator Previous | Decrement iteration index by -1 (Mode: Loop / Clamp at 0) | Index / List Variables / Mode |
| Iterator Random | Store a random value from 0 to element count in Index | Index / List Variables |
| Loop List | Iterate through a Game Object List and execute Actions for each element (sets Target to element each iteration) | List Variable / Actions |
| Move List | Move an element within a List to a different position | List Variable |
| Remove From List | Delete a specified element | List Variable |
| Reverse List | Reverse the order | List Variable |
| Shuffle List | Randomize the order | List Variable |
| Sort List Alphabetically | Sort by string (ascending/descending, Ignore Case option) | List Variable / Order / Ignore Case |
| Sort List By Distance | Sort by distance from a specified position (nearest/farthest) | List Variable / Position / Order |
| Swap List | Swap two elements in a List | List 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)
| Condition | Check | Main Parameters |
|---|---|---|
| List Is Empty | Returns true if the specified List Variable is empty | List 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.
| Event | Fires When |
|---|---|
| On Global Name Variable Change | A Global Name variable is modified |
| On Global List Variable Change | A Global List variable is modified |
| On Local Name Variable Change | A Local Name variable is modified |
| On Local List Variable Change | A 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
- Create a Global Name Variables asset and add
score : Number = 0 - In the Trigger’s Instruction when an item is collected, use
Increment Number→ add +10 toscore - On the UI Text side, set the Trigger’s Event to
On Global Name Variable Changeand useChange Textto redraw
Building an Enemy Lock-On Candidate List
- Attach Local List Variables to the Player, created as
targets : GameObjecttype - Use
Collect CharactersInstruction to collect Characters within 10m of the Player intotargets, withFilterset toTag == "Enemy" - Use
Sort List By Distanceto sort by distance from the Player - Use
Iterator Next/Iterator Randomto select, and pass to the Camera Shot’sChange Target
Referencing Equipped Weapon Durability via Nested Access
- Place Local Name Variables on the Player with
equipped : GameObject(current weapon reference) - Place Local Name Variables on each weapon Prefab with
durability : Number - The reference key is
equipped/durability(connected with a slash) - On attack, use a Set instruction to apply
-1toequipped/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 Signalwith"score-changed" - The UI side receives with
On Receive Signaland 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
intbut go through thePickabstraction. Use existing Pick implementations (first/last/random/specific index) or create custom Picks - Don’t mix types in Nested Access:
a/b/ctraverses 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 Intervalor use Signals for explicit notification - Using Properties dramatically increases reusability: Simply changing a custom component field from
public string foo;topublic PropertyGetString foo;lets you supply values from variables, Player references, and more
Unity Game Programming Bible 2nd GenerationView on Amazon →
The Game Developer's Map: Lessons from 20 Years of Solo DevelopmentView on Amazon →
Official Links
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).
We hope you’ll continue reading our next article as well.
📚 Series: Game Creator 2 Complete Guide (5/16)