Version: Unity 6.3 Beta (6000.3)
LanguageEnglish
  • C#

AnimatorController.CreateNewStateMachineBehaviour

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static EntityId CreateNewStateMachineBehaviour(MonoScript script);

Parameters

Parameter Description
script MonoScript class to instantiate.

Returns

EntityId Returns EntityId of created object, returns EntityId.None if something is not valid.

Description

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

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.

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 behaviour = EditorUtility.EntityIdToObject(entityId); AssetDatabase.AddObjectToAsset(behaviour, state.ToString()); } }