# Graph

> Represents the core definition of a graph and defines its behavior.

## Definition

* **Type:** Class
* **Namespace:** [Unity.GraphToolkit.Editor](/engine/6000.7/script-reference/unity/graphtoolkit/editor.md)
* **Assembly:** UnityEditor

```csharp
public class Graph
```

## Remarks

`Graph` serves as the central entry point for:

* Lifecycle management (via [Graph.OnEnable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/onenable.md), [Graph.OnDisable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/ondisable.md))

* Change tracking (via [Graph.OnGraphChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/ongraphchanged.md))

* Access to nodes and variables

To register a graph type and associate it with a custom file extension and configuration options, apply the [GraphAttribute](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphattribute.md) to your custom `Graph` class.

You can further control the graph's behavior using the [GraphOptions](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphoptions.md) enum, which defines traits such as support for subgraphs. If your graph supports subgraphs (via [GraphOptions.SupportsSubgraphs](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphoptions/supportssubgraphs.md)), you can declare valid subgraph types using the [SubgraphAttribute](/engine/6000.7/script-reference/unity/graphtoolkit/editor/subgraphattribute.md).

Use the [GraphDatabase](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphdatabase.md) 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](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphdatabase/promptinprojectbrowsertocreatenewasset.md) or load them from disk with [GraphDatabase.LoadGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graphdatabase/loadgraph.md).

## Properties

| Property                                                                                                            | Description                                                                                                                 |
| ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| [AssetGuid](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/assetguid.md)                           | The `GUID` of the asset file associated with this graph.                                                                    |
| [AvailableConstantTypes](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/availableconstanttypes.md) | The set of types offered in the graph item library for constant nodes.                                                      |
| [AvailableVariableTypes](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/availablevariabletypes.md) | The set of types offered in the blackboard for variable creation.                                                           |
| [ID](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/id.md)                                         | The globally unique identifier for this graph.                                                                              |
| [Name](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/name.md)                                     | The name of the graph.                                                                                                      |
| [NodeCount](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/nodecount.md)                           | The number of [INode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inode.md)s in the graph.                    |
| [SupportedTypes](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/supportedtypes.md)                 | The set of types supported by this graph, including all port types, available variable types, and available constant types. |
| [VariableCount](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/variablecount.md)                   | The number of [IVariable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/ivariable.md)s declared in the graph.   |

## Methods

| Method                                                                                                                        | Description                                                                                                                                                                                                                                                                                                    |
| ----------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [AddNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/addnode.md)                                         | Adds a node to the Graph.                                                                                                                                                                                                                                                                                      |
| [AddSubgraphNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/addsubgraphnode.md)                         | Creates and adds a new subgraph node referencing an existing Graph asset.                                                                                                                                                                                                                                      |
| [AddVariableNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/addvariablenode.md)                         | Creates and adds a new variable node referencing an existing variable.                                                                                                                                                                                                                                         |
| [BuildAvailableConstantTypes](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/buildavailableconstanttypes.md) | Builds the set of types offered in the graph item library for constant nodes.                                                                                                                                                                                                                                  |
| [BuildAvailableVariableTypes](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/buildavailablevariabletypes.md) | Builds the set of variable types offered in the blackboard for variable creation.                                                                                                                                                                                                                              |
| [Connect](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/connect.md)                                         | Creates a wire connection between two ports.                                                                                                                                                                                                                                                                   |
| [CreateConstantNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/createconstantnode.md)                   | Creates and adds a new constant node to the graph.                                                                                                                                                                                                                                                             |
| [CreateLocalSubgraphNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/createlocalsubgraphnode.md)         | Creates and adds a new local subgraph node.                                                                                                                                                                                                                                                                    |
| [CreateVariable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/createvariable.md)                           | Creates and adds a new variable to the graph.                                                                                                                                                                                                                                                                  |
| [Disconnect](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/disconnect.md)                                   | Removes the wire connection between two ports.                                                                                                                                                                                                                                                                 |
| [GetNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/getnode.md)                                         | Retrieves a node defined in the graph by its index.                                                                                                                                                                                                                                                            |
| [GetNodes](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/getnodes.md)                                       | Retrieves all nodes in the graph.                                                                                                                                                                                                                                                                              |
| [GetVariable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/getvariable.md)                                 | Retrieves a variable declared in the graph by index.                                                                                                                                                                                                                                                           |
| [GetVariables](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/getvariables.md)                               | Retrieves all variables declared in the graph.                                                                                                                                                                                                                                                                 |
| [GetWire](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/getwire.md)                                         | Gets the representation of the wire between an output port and an input port in the graph, if such a connection exists.                                                                                                                                                                                        |
| [IsConnectionAllowed](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/isconnectionallowed.md)                 | Determines whether a connection between the specified output and input ports is allowed.                                                                                                                                                                                                                       |
| [OnDefineSubgraphNodeOptions](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/ondefinesubgraphnodeoptions.md) | Called to define the [INodeOption](/engine/6000.7/script-reference/unity/graphtoolkit/editor/inodeoption.md)s available on subgraph nodes that reference this type of graph. Similar in function to [Node.OnDefineOptions](/engine/6000.7/script-reference/unity/graphtoolkit/editor/node/ondefineoptions.md). |
| [OnDisable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/ondisable.md)                                     | Called when the graph is unloaded, or goes out of scope in the editor.                                                                                                                                                                                                                                         |
| [OnEnable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/onenable.md)                                       | Called when the graph is created or loaded in the editor.                                                                                                                                                                                                                                                      |
| [OnGraphChanged](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/ongraphchanged.md)                           | Called after the graph has changed.                                                                                                                                                                                                                                                                            |
| [RemoveNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/removenode.md)                                   | Removes a node from the Graph.                                                                                                                                                                                                                                                                                 |
| [RemoveVariable](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/removevariable.md)                           | Removes a variable from the Graph.                                                                                                                                                                                                                                                                             |
| [UndoBeginRecordGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/undobeginrecordgraph.md)               | Signals the beginning of an undoable operation.                                                                                                                                                                                                                                                                |
| [UndoEndRecordGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/undoendrecordgraph.md)                   | 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.                                                                                                                                                                    |
