How to Trigger a Transition

To trigger a transition in a State Machine, call the Trigger method of the State Machine and pass the ID of the transition you want to trigger.

Example: Imagine you have the following State Machine and want to trigger the transition with the ID Show Settings.

The following two examples will show how you could achieve this with an UI Button in the inspector or from inside a script.

UI Button OnClick Example

Script Example

This script will trigger the transition with name Show Settings on the State Machine set in the inspector when the “S” key is down.

using Ilumisoft.VisualStateMachine; 
using UnityEngine; 
public class TriggerExample : MonoBehaviour 
{ 
    //Reference to the state machine set via the inspector 
    [SerializeField] StateMachine stateMachine = null; 
    
    private void Update() 
    { 
        if(Input.GetKeyDown(KeyCode.S)) 
        { 
            stateMachine.Trigger("Show Settings"); 
        } 
    } 
}

Last updated