Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Graph

Represents the core definition of a graph and defines its behavior.
Read time 3 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

AssetGuidThe
GUID
of the asset file associated with this graph.
AvailableConstantTypesThe set of types offered in the graph item library for constant nodes.
AvailableVariableTypesThe set of types offered in the blackboard for variable creation.
IDThe globally unique identifier for this graph.
NameThe name of the graph.
NodeCountThe number of INodes in the graph.
SupportedTypesThe set of types supported by this graph, including all port types, available variable types, and available constant types.
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.
BuildAvailableConstantTypesBuilds the set of types offered in the graph item library for constant nodes.
BuildAvailableVariableTypesBuilds the set of variable types offered in the blackboard for variable creation.
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.
GetWireGets the representation of the wire between an output port and an input port in the graph, if such a connection exists.
IsConnectionAllowedDetermines whether a connection between the specified output and input ports is allowed.
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.