Game Creator properties are a special type of class that allows 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 to write maintainable and decoupled code.
Properties take advantage of Unity's polymorphic serialzation, 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:
- Target: A reference to the
Game Objectresponsible for calling the property
- Self: A reference to the
Game Objectcontaining the property reference.
There are some cases where the
Self fields will reference the same game object.
Property Get types allow to retrieve a value and Property Set types allow 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 Get Types¶
There are a few default property types available:
PropertyGetBool: A boolean value type
PropertyGetColor: A representation of a Color
PropertyGetDecimal: A decimal value
PropertyGetDirection: A Vector3 representing a direction
PropertyGetGameObject: References a game object
PropertyGetInstantiate: Allows to reference an instance
PropertyGetInteger: An integer value
PropertyGetLocation: A position and/or rotation
PropertyGetOffset: A Vector3 that offsets from a position
PropertyGetPosition: A Vector3 representing a point in space
PropertyGetRotation: A Quaternion representing a rotation
PropertyGetScale: A Vector3 representing a scalar value
PropertyGetScene: Allows to select scene objects
PropertyGetSprite: Returns Sprite assets
PropertyGetString: Returns texts
PropertyGetTexture: To retrieve Texture assets
PropertyGetTransform: For Transform components
Property Set Types¶
PropertySetBool: Sets a boolean value
PropertySetColor: Sets a Color type value
PropertySetGameObject: Sets a game object reference
PropertySetNumber: Sets a numeric value
PropertySetSprite: Sets a Sprite reference
PropertySetString: Sets a text-based value
PropertySetTexture: Sets a Texture asset reference
PropertySetVector3: Sets a Vector3 type value
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
string value = this.myValue.Get(args);
Args (arguments) class is a two-field struct that contains the game object considered as the source of the call as well as the targeted game object. 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);