-
-
Notifications
You must be signed in to change notification settings - Fork 592
Ports
Thor Brigsted edited this page Dec 10, 2019
·
14 revisions
class NodePort
Ports are the gates to communication between nodes. They can be either an input or an output, has a reference to its parent node, and contains methods to return connected ports. They have a type variable, which defines the color of the node, and potentially which other nodes it can connect to. Some ports are dynamic.
Ports can be added by adding either an [Input] or an [Output] attribute to serialized variable. General rule of thumb is; if Unity can serialize it, it can be a port.
You might want to dynamically add and remove ports. Read more about dynamic ports.
Typical usage of ports include (in a node class):
// Get the connected node.
NodePort otherPort = GetOutputPort("myOutput").Connection
if (otherPort != null) {
MyNode nextNode = otherPort.node as MyNode;
}
// Get the sum of all number inputs added together
return GetInputPort("myInput").GetInputSum(myInput);
Port attributes also support a number of parameters:
- backingValue - When to show the backing field value.
- connectionType - How many connections to allow for this port
- dynamicPortList - If true, will display a port per list item instead of one port for the entire list
- typeConstraint - Limit which value types you can connect to this port