Skip to content

Node.[Input Output]

Thor Brigsted edited this page Nov 14, 2018 · 4 revisions
public [Input(ShowBackingValue backingValue, ConnectionType connectionType, bool instancePortList = false)];
public [Output(ShowBackingValue backingValue, ConnectionType connectionType, bool instancePortList = false)];
Parameters Summary
backingValue When to show the field inspector associated with this NodePort.
connectionType Should we allow multiple connections?
instancePortList Display a reoderable list of ports, optionally using array data as backing values

Assign an input or output port to a public or private serialized field.

public class ExampleNode : Node{
    [Input] public float a;
    [Output] public float b;
}

Instance port lists

If you need a dynamic list of ports instead of a single port, consider setting instancePortList to true

eg. [Input(instancePortList = true)]

This will transform the field into a reorderable list of ports with add and remove buttons. If the field is an array or list type, a value will also be displayed for each element.

Customize instance port lists

You may want to customize the way the list is drawn. You can do this by modifying the list delegates after the list is created, by hooking into NodeEditorGUILayout.onCreateReorderableList.

public class MyNodeEditor : NodeEditor {
    public override void OnBodyGUI() {
        // Add our delegate to catch new reorderable lists while our GUI is drawing
        NodeEditorGUILayout.onCreateReorderableList += OnCreateReorderableList;

        // Draw GUI
        base.OnBodyGUI():

        // Remove delegate again. We don't want to catch from other nodes
        NodeEditorGUILayout.onCreateReorderableList -= OnCreateReorderableList;
    }

    void OnCreateReorderableList(ReorderableList list) {
        // Override drawHeaderCallback to display node's name instead
        list.drawHeaderCallback = (Rect rect) => {
            string title = serializedObject.targetObject;
            EditorGUI.Label(rect, title);
        };
    }
}
Clone this wiki locally