Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Graph

Represents the core definition of a graph and defines its behavior.
Read time 2 minutesLast updated 6 days ago

Definition

public class Graph

Remarks

Graph
serves as the central entry point for:
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.

Properties

Property

Description

NameThe name of the graph.
NodeCountThe number of INodes in the graph.
VariableCountThe number of IVariables declared in the graph.

Methods

Method

Description

AddNodeAdds a node to the Graph.
AddSubgraphNodeCreates and adds a new subgraph node referencing an existing Graph asset.
AddVariableNodeCreates and adds a new variable node referencing an existing variable.
ConnectCreates a wire connection between two ports.
CreateConstantNodeCreates and adds a new constant node to the graph.
CreateLocalSubgraphNodeCreates and adds a new local subgraph node.
CreateVariableCreates and adds a new variable to the graph.
DisconnectRemoves the wire connection between two ports.
GetNodeRetrieves a node defined in the graph by its index.
GetNodesRetrieves all nodes in the graph.
GetVariableRetrieves a variable declared in the graph by index.
GetVariablesRetrieves all variables declared in the graph.
OnDefineSubgraphNodeOptionsCalled to define the INodeOptions available on subgraph nodes that reference this type of graph. Similar in function to Node.OnDefineOptions.
OnDisableCalled when the graph is unloaded, or goes out of scope in the editor.
OnEnableCalled when the graph is created or loaded in the editor.
OnGraphChangedCalled after the graph has changed.
RemoveNodeRemoves a node from the Graph.
RemoveVariableRemoves a variable from the Graph.
UndoBeginRecordGraphSignals the beginning of an undoable operation.
UndoEndRecordGraphSignals the end of an undoable operation. Sends the undo data to the editor undo system and refreshes the graph view with the changes made.