Introduction
This new feature comes in to address a few rather old issues with Construct, which are the following:
- Updating several instances of the same object type with different initialization properties could prove to be time consuming and prone to error. Specially in large layouts or across multiple layouts.
- No way to define pre-sets when creating an instance at runtime using the Create Object action. Up until now you had to create the instance and then set it's properties in the event sheet.
- No way to choose a specific hierarchy to create at runtime, if multiple were created in the editor using the same type of instance as the root. This forced you to use unique instances as roots in order to guarantee the hierarchy that would be created at runtime.
Granted those three issues could be worked around, from now on you won't have too anymore.
New terms
There are two new terms that will be used in this guide.
- Template: an instance that has been set to be the source of property values for other instances to use. These include, common instance properties, plugin properties, instance variables, behaviour properties and effect parameters. A template can also be used to decide what values a new instance created at runtime should take when using the Create Object action. Modifying a template in the Layout view or through the Properties bar will immediately be reflected in all instances which are replicas of it.
- Replica: an instance that has been set to use an instance already defined as a template. A replica takes it's values from the source template unless they are explicitly modified, at which point the replica's own values are used.
How does it work?
The Properties bar now shows a few new properties when selecting an instance.
Properties bar |
Property descriptions |
|
- Template mode: an instance can be turned into a template by selecting the "Template" value from the drop down menu. If there are any instances in the object type which have already been set to be a template, then the "Replica" value will also be available in the drop down menu.
- Template name: the name to identify a template. This input is only active when Template mode equals to "Template".
- Template source: the name of the template a replica is using. Only shows templates of the same object type as the replica. The drop down is only active when Template mode equals to "Replica".
|
To start using this feature the first thing you will need to do is set an instance to be a template. To do that, follow these steps:
- Select the instance you want to be a template in the Layout view.
- Pick the "Template" option from the Template mode dropdown in the Properties bar.
- Give the template a name using the Template name text input.
That's all you need to do to set an instance to be a template.
Now let's see how to set other instances to use the template in the editor:
- Select the instance you want to be a replica of the template in the Layout View. The instance must be of the same object type as the template.
- Pick the "Replica" option from the Template mode dropdown.
- Select the template the replica instance should use from the Template source dropdown.
After doing that you will notice that some of the properties in the Properties bar are highlighted, this indicates that the instance is taking that value from the source template.
From now on, when the template is modified, all replicas using it, will reflect the changes. If a replica is modified individually, the affected property will stop taking the value from the template and instead will take the value from the replica itself. To indicate this, the property will no longer be highlighted.
Miscellaneous options
Layout view context menu options
Template context menu |
Replica context menu |
|
|
- Template instance context menu options:
- Apply template to all replicas: force all replicas using this template to use the values of the template.
- Select all replicas in layout
- Open all layouts with replicas: opens all layouts with replicas of the selected template.
- Replica instance context menu options:
- Use all values from template: forces the selected replica to use the values from the template.
- Select all replicas in layout
- Open template layout: open the layout containing the template the selected replica is using.
Properties bar context menu options
When a replica's property is modified and because of that it starts using it's own value, it is possible to individually set it back to use the template value by right clicking on the property name in the properties bar.
Runtime actions
The Create Object system action now has an additional Template parameter. When specified the new instance being created will be made to be a clone of the template instance, rather than an arbitrary one.
Asides from using the properties of the template instance, the new instance will also pick up the hierarchy from the template, if one exists. This means that it is now possible to create different hierarchies in the editor that use the same type of instance as a root, while also being able to choose which one to create at runtime.
Considerations
This is the first version of this feature so there are still a few things to iron out. The following are a few things which are not immediately obvious.
- By default, replicas do not use the position properties of the template. In most cases it is more useful for these two properties to remain individual for each replica.
- The Spawn another object action of Sprite is not yet supported.
- At runtime, replicas are no longer connected to their templates as they are in the editor. This means that changing a template at runtime, will not affect the replicas. This applies for properties and hierarchy changes.
- In the editor, adding or removing children from a template will not be reflected on the replicas. This could be added in the future.
Here is an example project that can be opened in r286, showing how the feature is used.
dropbox.com/s/ewh9h1js5ocu46a/Templates%20Example.c3p
This is it for now. This is the first version, so there is still work to be done.