Graph
Represents the core definition of a graph and defines its behavior.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Class
- Namespace: Unity.GraphToolkit.Editor
- Assembly: UnityEditor
public class Graph
Remarks
Graph-
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 class.
GraphYou 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.
Properties
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. |
Methods
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. |
| Connect | Creates a wire connection between two ports. |
| 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. |
| Disconnect | Removes the wire connection between two ports. |
| 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. |
| OnDefineSubgraphNodeOptions | Called to define the INodeOptions available on subgraph nodes that reference this type of graph. Similar in function to Node.OnDefineOptions. |
| 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. |
| UndoBeginRecordGraph | Signals the beginning of an undoable operation. |
| UndoEndRecordGraph | Signals the end of an undoable operation. Sends the undo data to the editor undo system and refreshes the graph view with the changes made. |