Skip to content
Thor Brigsted edited this page Jun 15, 2018 · 23 revisions

Any class deriving from Node is automatically registered as a node in the graph editor, and can be added via the right-click menu. A simple node with a single input and a single output can look like this:

public class SimpleNode : Node {
    [Input] public float value;
    [Output] public float result;
}

When another node asks for the output of this node, the method object GetValue(NodePort port); is called. You need to override it in order to have your node return something sensible. In this example, we will just return the input value.

// Returns value + 1
public class SimpleNode : Node {
    [Input] public float value;
    [Output] public float result;

    public override object GetValue(NodePort port) {
        // Check which output is being requested. 
        // In this node, there aren't any other outputs than "result".
        if (port.fieldName == "result") {
            // Return input value + 1
            return GetInputValue<float>("value", this.value) + 1;
        }
    }
}

Init

Each node calls Init on start. If you, as an example, want to modiy the name of a node on creation, you can do so by overriding Init.

public void Init() {
    name = "MyName";
}

Creation context menu

By default, the context menu path will be based upon namespace and class name. If you wish to change this, you can use the [CreateNodeMenu] class attribute. Simply add it to your class and supply it with your desired path.

  • [CreateNodeMenu("MyMathNodes/Subtraction")]

Alternatively, you can hide a node from the context menu by supplying a null or empty string to the attribute.

  • [CreateNodeMenu("")]

Context menu

Nodes support the [ContextMenu] attribute. Simply add [ContextMenu] to a non-static method and it will show up when you right-click the node header. Select it to execute the method. You can read more about it here

Colors

Nodes types can be tinted for easier grouping and overview. To do this, simply add a [NodeTint] attribute to your node class, and supply it with either a hex color string, or 3 floats representing rgb.

  • [NodeTint("#ffaaaa")]
  • [NodeTint(1.0f, 0.8f, 0.8f)]
Clone this wiki locally