# CreateConstantNode

> Creates and adds a new constant node to the graph.

## Definition

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

## CreateConstantNode(Vector2, Type, Object)

Creates and adds a new constant node to the graph.

```csharp
public IConstantNode CreateConstantNode(Vector2 position, Type valueType, object defaultValue = null)
```

### Parameters

**** (\[Vector2]\(/engine/6000.7/script-reference/unityengine/vector2)): The position of the node.**** (\[Type]\(https\://learn.microsoft.com/dotnet/api/system.type)): The type of the value held by the constant.**** (\[Object]\(https\://learn.microsoft.com/dotnet/api/system.object)): The default value.

### Returns

| Type                                                                                        | Description                      |
| ------------------------------------------------------------------------------------------- | -------------------------------- |
| [IConstantNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/iconstantnode.md) | The newly created constant node. |

### Remarks

If successful, also adds the node's type to the graph's list of supported types. Enclose this method with [Graph.UndoBeginRecordGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/undobeginrecordgraph.md) and [Graph.UndoEndRecordGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/undoendrecordgraph.md) to add this operation to the undo stack and to update the graph view with the changes.

## CreateConstantNode\<T>(Vector2, T)

Creates and adds a new constant node to the graph.

```csharp
public IConstantNode CreateConstantNode<T>(Vector2 position, T defaultValue = default)
```

### Parameters

**** (\[Vector2]\(/engine/6000.7/script-reference/unityengine/vector2)): The position of the node.**** (T): The default value.

### Returns

| Type                                                                                        | Description                      |
| ------------------------------------------------------------------------------------------- | -------------------------------- |
| [IConstantNode](/engine/6000.7/script-reference/unity/graphtoolkit/editor/iconstantnode.md) | The newly created constant node. |

### Remarks

If successful, also adds the node's type to the graph's list of supported types. Enclose this method with [Graph.UndoBeginRecordGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/undobeginrecordgraph.md) and [Graph.UndoEndRecordGraph](/engine/6000.7/script-reference/unity/graphtoolkit/editor/graph/undoendrecordgraph.md) to add this operation to the undo stack and to update the graph view with the changes.
