Graph
Represents the core definition of a graph and defines its behavior.
Read time 3 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 |
|---|---|
| AssetGuid | The |
| AvailableConstantTypes | The set of types offered in the graph item library for constant nodes. |
| AvailableVariableTypes | The set of types offered in the blackboard for variable creation. |
| ID | The globally unique identifier for this graph. |
| Name | The name of the graph. |
| NodeCount | The number of INodes in the graph. |
| SupportedTypes | The set of types supported by this graph, including all port types, available variable types, and available constant types. |
| 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. |
| BuildAvailableConstantTypes | Builds the set of types offered in the graph item library for constant nodes. |
| BuildAvailableVariableTypes | Builds the set of variable types offered in the blackboard for variable creation. |
| 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. |
| GetWire | Gets the representation of the wire between an output port and an input port in the graph, if such a connection exists. |
| IsConnectionAllowed | Determines whether a connection between the specified output and input ports is allowed. |
| 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. |