Hierarchy and Inheritance
Properties in UNIGINE can form a hierarchy. However, there are certain rules and constraints described below, that must be taken into account.
Properties Hierarchy#
Properties hierarchy is formed by inheriting one property from another. A parent property passes all its parameters to its children so that they can be overridden, much like in object-oriented programming.
At the top of the hierarchy there are base properties. Unigine provides 2 built-in read-only base properties: node_base and surface_base. You can also make custom base properties of your own.
It is also recommended to inherit properties that will be assigned to nodes from the node_base property. However, you can also assign any custom base property or its children to a node.
Base properties cannot have a parent: no base property can be inherited from another base property. The values of parameters of manual properties (including base ones) cannot be changed. So, to modify parameters of a manual property via the UnigineEditor, you should inherit a user property from it.
The parent of a user property can be changed by dragging it to a new parent in the Properties Hierarchy window.
Taking all abovementioned into account, there are the following reasons to create properties hierarchy:
- Inheriting from a base property allows editing its parameters via the UnigineEditor.
- Inheriting from a user property allows for mass controlling values of multiple property parameters.
Properties Loading Order#
Properties hierarchy doesn't affect the loading order of properties.
Referring to Properties by GUIDs#
A GUID (Globally Unique Identifier) is an identifier for a property. It represents a 40-character hexadecimal string generated using the SHA-1 hash algorithm.
Properties hierarchy is based on GUIDs: all properties are referred to using GUIDs, even base and manual ones (the GUIDs for such properties are generated at run time and are uniquely determined by their names). However, only user properties store their GUIDs explicitly: a GUID is generated automatically on user property creation and is written to the corresponding *.prop file.
For example:
<property version="2.13.0.1" name="surface_base_0" guid="2750c68c5a8d5e01198c9a32ba6ffaa46ae31b8c" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
The GUID of a user property is stored in the guid attribute. If user property is inherited from another user property, it will refer to the parent by its GUID (see the parent attribute in the example above).
Using GUIDs makes it difficult to edit user properties manually. For example, to rename such property, it is required to generate a GUID for the new name and replace the current GUID.
As GUIDs for manual properties (including base ones) are uniquely determined by their names, changing the name of such property will also change its GUID. That is why manual properties cannot be renamed at run time. For the same reason, *.prop files of such properties store only their names, not GUIDs. Manual properties usually use name-based references to other manual properties (including base ones).
Types of Inheritance#
As it was mentioned above, base properties, which are all manual, are always at the top of the hierarchy, while other properties are inherited from them. You can inherit:
- a new user property from any other property via the UnigineEditor.
- a new manual property from another manual property (including base one) by creating a new *.prop file with a name-based reference to the parent.
So, basically we can have the following types of inheritance:
- Manual Parent - Manual Child
- Manual Parent - User Child
- User Parent - User Child
Thus, depending on the type of inheritance, the *.prop file of a child property will store a reference to its parent as follows:
- Parent: manual property (including base ones).
- If the inherited property is also manual, the corresponding *.prop file stores the name of the property, and the name of its parent in the parent_name attribute.
Only manual properties can refer to their parent manual property by name.
<property version="2.13.0.1" name="my_node_base1" parent_name="node_base" manual="1"/>
- If the inherited property is not manual (i.e it is a user property), the corresponding *.prop file stores a GUID of the user property, and the GUID of its parent (generated at run time from the parent's name) in the parent attribute.
<property version="2.13.0.1" name="my_node_base2" guid="cccd50e4431ddaeaf01dcb394fc988def578b380" parent="d99ebc8ef5769d70b1e46992309cc3e7d1aa2faa"/>
- If the inherited property is also manual, the corresponding *.prop file stores the name of the property, and the name of its parent in the parent_name attribute.
- Parent: user property. The *.prop file of the inherited user property stores a GUID of the user property, and the GUID of its parent in the parent attribute.
<property version="2.13.0.1" name="my_node_base3" guid="cd3ebc8ef5769d70b1e46452309cc3e7d1aa2ccd" parent="cccd50e4431ddaeaf01dcb394fc988def578b380"/>