# CreateStateMachineBehaviour(MonoScript)

> This function will create a StateMachineBehaviour instance based on the class define in this script.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Animations](/engine/6000.5/script-reference/unityeditor/animations.md)
* **Assembly:** UnityEditor.CoreModule

> **Warning:**
>
> **Removed.** CreateStateMachineBehaviour is deprecated. Use CreateNewStateMachineBehaviour instead.

```csharp
public static int CreateStateMachineBehaviour(MonoScript script)
```

### Parameters

**** (\[MonoScript]\(/engine/6000.5/script-reference/unityeditor/monoscript)): MonoScript class to instantiate.

### Returns

| Type                                                       | Description                                                                 |
| ---------------------------------------------------------- | --------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | Returns instance id of created object, returns 0 if something is not valid. |

### Remarks

This function will validate that the monoscript is a valid statemachine behaviour, the class must be a sub class of StateMachineBehaviour and shouldn't be a generic. Additional Resources: [StateMachineBehaviour](/engine/6000.5/script-reference/unityengine/statemachinebehaviour.md).

### Examples

```csharp
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

public class AddSMB
{
    public void DoAddStateMachineBehaviour(UnityEditor.Animations.AnimatorState state, MonoScript monoScript)
    {
        if (state == null)
            return;

        EntityId entityId = AnimatorController.CreateNewStateMachineBehaviour(monoScript);
        if (entityId == EntityId.None)
        {
            Debug.LogError("Could not create state machine behaviour " + monoScript.name);
            return;
        }

        state.AddStateMachineBehaviour(monoScript.GetClass());

        var obj = EditorUtility.EntityIdToObject(entityId);
        if (obj == null)
            Debug.LogError("No object could be found with entity id: " + entityId);
        else
            AssetDatabase.AddObjectToAsset(obj, state.ToString());
    }
}
```
