Skip to content

Properties

Game Creator properties are a special type of class that allows you to dynamically specify the source of a field value using a dropdown menu. The menu's options are dynamic and can be added without the need of overwriting Game Creator core code, allowing you to write maintainable and decoupled code.

Polymorphic Serialization

Properties take advantage of Unity's polymorphic serialization, which means that the dropdown menu options are decoupled from the core code. Anyone can plug in their own menu options without overwriting any scripts.

There are different types of Properties, each with its own set of options. All of them have in common that, when retrieving them, an instance of Args parameter is passed, which contains two fields:

  • Self: A reference to the Game Object that contains the property reference, which is also the one that initiates the call.
  • Target: A reference to the Game Object that is targeted by the call, if any.

Args Parameter

There are some cases where the Target and Self fields will reference the same game object.

Property Get types allow you to retrieve a value and Property Set types allow you to set a value. Game Creator comes with a collection of both types, but each module increases the amount available. You can even create your own property types to extend the existing ones.

Property Types

There are multiple default property types available, which start with PropertyGet and end with the type. For example PropertyGetDecimal is the property type for decimal numeric values, PropertyGetInteger is the one for whole numbers and PropertyGetBool is the analog for boolean (true/false) values.

There are also property setters, which allow you to set the value of a property. They start with PropertySet and also end with the type name. For example the PropertySetGameObject allows you to set the value of a game object reference.

Using Properties

UI Toolkit

Using properties requires the Editor scripts to be written using Unity's UI Toolkit. IMGUI is not supported.

To use a property it's very simple. You just need to declare them as you would with a primitive type, but instead of getting the value directly, call the Get(args) method to retrieve its value.

For example, let's say that in a component, you want to get a string value. Instead of declaring a value like this:

public string myValue = "This is my string";

You could use a property so the source of that string value isn't hard-coded, but set from the Inspector. Like this:

public PropertyGetString myValue = new PropertyGetString();

This will display a dropdown menu on the Inspector with the current option selected. By default it's a constant string, but the value can be chosen to come from the name of a game object, a local or global variable, etc.

To get the value you simply call the Get(args) method:

string value = this.myValue.Get(args);

Args

The Args (arguments) class contains the game object considered as the source of the call (Self) as well as the targeted game object (Target). This class is necessary in order to use properties that reference the "Self" or "Target" values. If you are not sure what the self and target objects are, simply pass in the current MonoBehaviour's game object:

Args args = new Args(this.gameObject);

Creating Properties

Just like Instructions and other visual scripting nodes, one can create custom properties to interact with other assets or custom code. To create a new GET Property simply inherit the PropertyTypeGet[TYPE] class.

Example of a custom number property

For example let's say we want to create a custom number GET property that always returns 42 (for some reason). In that case we create a new script that inherits from PropertyTypeGetDecimal called GetDecimal42:

[Serializable]
public class GetDecimal42 : PropertyTypeGetDecimal
{
    public override double Get(Args args)
    {
        return 42;
    }

    public override string String => "42";
}

Adding fields

You can also expose fields just like you would do in a custom Inspector script. For example, if you want to display a number field which will be returned by the property you can do so:

[Serializable]
public class GetDecimalMyNumber : PropertyTypeGetDecimal
{
    [SerializeField] private double m_Number = 42;

    public override double Get(Args args)
    {
        return this.m_Number;
    }

    public override string String => this.m_Number.ToString();
}

You can add as many fields as you want. Even other properties.

To return the value the Get(args) method must be implemented. The Args parameter contains the Self and Target values calling the property, which can be used to dynamically get the final value if necessary.

The String property must also be implemented. It returns the text that is displayed for this option in the Unity Inspector.

Property classes can also be decorated with the Title, Category, Description and other attributes, just like it is done on Instructions and other visual scripting nodes.