Property
A property exposes data outside the graph for external objects to consume or to push information to the graph instance. A property can be either an asset that's instantiated by the graph, or an instance reference consumed by the graph.
Use properties when a value has to be set from outside the graph, while you would use bindings when a value is closely contained within a node and not used within a graph. A property is more modular than a binding. You can share properties across multiple node instances within a graph, while bindings are self-contained within a single node instance.
Defining Properties
To define properties we need to create two classes, one for the NodeRuntime which the property will exist as during runtime:
[NodeCategory("Type", "String", NodeTick.Asynchronous,
Mode = NodeMode.Standard | NodeMode.Property)]
public class NodeString : NodeRuntime
{
static Type PropertyType = typeof(StringProperty);
[Field("Data", PortDirection.Right, FieldExtra.Write | FieldExtra.Constant)]
[SerializeField]
public PortType<string> data = new PortType<string>();
}
This runtime node behaves as any other asynchronous node will, and we can override the Enable() method to perform any graph start up logic. Note that each instance of the property in the graph will call Enable(), even though they will share the same property value given from outside the graph.
To receive data from outside the graph, you must also create a Property type for our node:
[NodeProperty("String"), AddComponentMenu("")]
public class StringProperty : Property<string> {}
The attribute NodeProperty(string NodeType)
creates the correspondence between the spawned runtime node and the property.
Note
Private fields will not by default be shown in the Unity inspector. If you want to use a private field, then the Bind()
function can be used. The Bind()
function is called before any link is refreshed in the graph. This function can do anything that is required before the link between the property and the runtime instance.
Property defined in the SystemGraph Editor
When editing a system graph, you can view the list of properties and add new ones using the Blackboard. You can drag properties from the Blackboard into the graph, where they appear as nodes with a single port.
System Graph Component Inspector
You can attach a System Graph Component to a GameObject representing a top-level system. When you select the GameObject, the graph properties appear in the Inspector window, under the System Graph Component, allowing you to edit input properties to configure the graph or connect it to other GameObjects in the scene.