> For the complete documentation index, see [llms.txt](https://ilumisoft.gitbook.io/visual-state-machine/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ilumisoft.gitbook.io/visual-state-machine/get-started/how-to-trigger-a-transition.md).

# 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.&#x20;

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

<figure><img src="https://3979764177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCgKLjperRFhHlR4O0p%2Fuploads%2FBmVGql1BDcVwrUiMCLLC%2Fimage.png?alt=media&amp;token=8aa2229e-7cd0-40ee-849c-6125589f2e7a" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://3979764177-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCgKLjperRFhHlR4O0p%2Fuploads%2FzNpxzB4QREbCXdbVYxj9%2Fimage.png?alt=media&amp;token=9f67a45d-c4c6-4fec-aedb-8c57032033e9" alt=""><figcaption></figcaption></figure>

### Script Example&#x20;

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"); 
        } 
    } 
}
```
