Home »API Reference»Accessing a PlayMakerFSM in Scripts
Index

Accessing a PlayMakerFSM in Scripts

There are a few ways to reference a PlayMakerFsm in your scripts:

1. Add a public PlayMakerFSM variable and link to the component.

A simple example:

2. Use GetComponent to get an PlayMakerFSM Component on a GameObject.

Javascript example:


var LivesFSM : PlayMakerFSM;

//assign the FSM on the Lives obj
LivesFSM = gameObject.FindWithTag("Lives").GetComponent.<PlayMakerFSM>();
        
var LivesRemaining : int;
LivesRemaining= LivesFSM.FsmVariables.GetFsmInt("Remaining_Lives").Value;

Another Javascript example:

3. Use GetComponents and the FsmName property to find a specific FSM on a GameObject that has multiple FSMs

Get all PlayMakerFSM components on a GameObject using GetComponents<PlayMakerFSM>(), then loop through them and find the one with the right FsmName.