Represents the core definition of a graph and defines its behavior.
Graph serves as the central entry point for:
Lifecycle management (via Graph.OnEnable, Graph.OnDisable)Change tracking (via Graph.OnGraphChanged)Access to nodes and variables
To register a graph type and associate it with a custom file extension and configuration options,
apply the GraphAttribute to your custom Graph class.
You can further control the graph's behavior using the
GraphOptions enum, which defines traits such as support for subgraphs.
If your graph supports subgraphs (via GraphOptions.SupportsSubgraphs), you can declare valid subgraph types
using the SubgraphAttribute.
Use the GraphDatabase utility class to create, load, and save graph assets in the Unity Editor.
Graphs are serialized assets. You can create them through the editor UI with
GraphDatabase.PromptInProjectBrowserToCreateNewAsset or load them from disk with
GraphDatabase.LoadGraph.
| Property | Description |
|---|---|
| Name | The name of the graph. |
| NodeCount | The number of INodes in the graph. |
| VariableCount | The number of IVariables declared in the graph. |
| Method | Description |
|---|---|
| AddNode | Adds a node to the Graph. |
| AddSubgraphNode | Creates and adds a new subgraph node referencing an existing Graph asset. |
| AddVariableNode | Creates and adds a new variable node referencing an existing variable. |
| CreateConstantNode | Creates and adds a new constant node to the graph. |
| CreateLocalSubgraphNode | Creates and adds a new local subgraph node. |
| CreateVariable | Creates and adds a new variable to the graph. |
| GetNode | Retrieves a node defined in the graph by its index. |
| GetNodes | Retrieves all nodes in the graph. |
| GetVariable | Retrieves a variable declared in the graph by index. |
| GetVariables | Retrieves all variables declared in the graph. |
| OnDisable | Called when the graph is unloaded, or goes out of scope in the editor. |
| OnEnable | Called when the graph is created or loaded in the editor. |
| OnGraphChanged | Called after the graph has changed. |
| RemoveNode | Removes a node from the Graph. |
| RemoveVariable | Removes a variable from the Graph. |
| Method | Description |
|---|---|
| OnDefineSubgraphNodeOptions | Called to define the INodeOptions available on subgraph nodes that reference this type of graph. Similar in function to Node.OnDefineOptions. |