Retrieve Playmaker variable from code

ingredients needed : UnityPlaymaker

If we have created some variables in Playmaker like a boolean, we can retrieve it with this code snippet, place under an object that is using a FSM window.

Retrieve local variables

In this example we got a FSM boolean called “foo” :

using HutongGames.PlayMaker;
 
private PlayMakerFSM MyFsm;
 
void Awake(){
//used for retrieve the FSM attached to the gameObject
MyFsm = this.GetComponent();
}
 
FsmBool fooVar = MyFsm.FsmVariables.FindFsmBool("foo").Value;

Retrieve global variables

In case we have a global FSM variable called “globalFoo” :

using HutongGames.PlayMaker;
 
private PlayMakerFSM MyFsm;
 
void Awake(){ 
//used for retrieve the FSM attached to the gameObject 
MyFsm = this.GetComponent(); 
}
FsmBool fooVar =MyFsm.GlobalVariables.FindFsmBool("globalFoo").Value;

Leave a Reply