When you add variables to an object, any instance of the object put on the scene or created during the game will have those variables attached to it. Ex: you can have a variable called Life representing the health of the object.
- are stored in memory for as long as a specific instance of an object exists.
- can be accessed by the instance of the object.
They're useful for storing data associated with individual instances of an object, such as the amount of health an enemy has. They're deleted from memory when the instance is removed from the scene.
The terms object variable, instance variable, and object instance variable are used interchangeably.
Creating object variables
- Open the Scene editor.
- Open the object editor of the object that you want to add the variable to.
- Open the Variables tab.
- Click Add.
- Enter a name for the variable.
- (Optional) Enter a default value for the variable.
- Select Apply.
Variable names should not contain dots (periods) or commas. We recommend using alphanumerical characters.
Using object variables in expressions
You can use object variables in expressions. The syntax depends on the data type of the variable. In the examples below, replace the placeholders in angled brackets with the relevant values.