The SetByDerived property enables base Entities to define objects which will be assigned (instantiated) in derived Entities. Keep in mind that both the base and derived Object type must be the same. In other words, if the base Entity has a Sprite Object, then the Entity that derives from the base must also define the object as a Sprite (see below for example).
SetByDerived makes an object “null”
If you set the SetByDerived property on an object to true, that means that Glue will not create that object in the Screen or Entity that contains this Object in generated code. This Screen or Entity must be used as a base Screen or Entity to actually create an object.
For example, consider an Entity called Character which contains a Sprite Object with SetByDerived set to true. The Sprite will not be created if you add an instance of Character to another Screen or Entity. The Character must be used as a base for another Entity (such as an Entity called “Monster”).
The following shows how to create an Entity (Base) which defines a Sprite Object which will get SetByDerived. The Derived then re-defines the Sprite.
Creating a Base Entity
- Right-click on the tree item
- Select Add Entity
- Name the entity Base
- Check the Sprite checkbox to add a Sprite to the Base entity
- Click OK
Creating a Derived Entity
- Right-click on the Entities tree item
- Select Add Entity
- Name the entity Derived
- Click OK
- Click the Properties tab on the newly-created Derived entity
- Set the BaseEntity property Entities\Base
Base and Derived are bad names!
This example uses the names “Base” and “Derived” to clearly indicate the relationship between two Entities. In an actual game, avoid using names like Base and Derived. You should always name your Entities in a way to indicate what they are in the context of your game (such as Character or Enemy or PlayerShip). However, if you intend to use an Entity as a base type, it is a good idea to append “Base” at the end of the name (such as EnemyBase).
Setting SetByDerived to True
- Expand the Base entity
- Select SpriteInstance (which was created earlier when the Sprite checkbox was checked)
- Select the Properties tab
- Set the SpriteObject’s SetByDerived to True
Glue will automatically add a SpriteInstance to the Derived entity.
Notice that objects which have their SetByDerived property to true appear blue in the tree view window, and objects which have their base implementation marked as SetByDerived appear yellow.
Specifying Properties on Derived Sprite
At this point the Derived entity will automatically create a Sprite for you (since it is an object in Glue). You can select this Sprite and assign variables on it, just like any other Sprite.
SetByDerived and Multiple Inheritance Levels
By default SetByDerived applies to only one level of inheritance, rather than cascading down through all levels of inheritance. For example, consider an example with three entities:
- Middle (which inherits from Base)
- Derived (which inherits from Middle)
If Base defines SpriteInstance, and SpriteInstance has its SetByDerived to true, then the assignment to SpriteInstance will be done in Middle, and Derived will not be able to re-assign Sprite.
Notice in the image above that SpriteInstance does not appear in the Derived entity.
However, the SetByDerived property can be set on the Middle SpriteInstance, and it will be assignable in Derived.