Skip to content
Thor Brigsted edited this page Mar 7, 2019 · 12 revisions
class NodeGraph : ScriptableObject

What?

Every xNode project starts with the creation of a graph. The graph contains a list of nodes, and what you decide to do with those nodes is up to you.

Why?

Your graph should act as the topmost entry point for your nodes. Depending on your needs, you can implement methods such as GetFirstNode, GetRootNode, GetResult, UpdateAI etc. inside your graph. It can also be used to contain variables that all your nodes rely on, perhaps a currentNode field for a state machine.

How?

Nodes are accessible through the nodes variable, and looping through it is your main entrance point to your graph.

[CreateAssetMenu]
public class SimpleGraph : NodeGraph { 

  public RootNode GetRootNode() {
    for (int i = 0; i < nodes.Count; i++) {
      if (nodes[i] as NewNode) return nodes[i] as NewNode;
    }
    return null;
  }
}

Context menu

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

Clone this wiki locally