Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: amaranth on September 28, 2012, 02:11:24 PM

Title: set Target FSM via script (UIEventsToPlaymakerFSM)[SOLVED]
Post by: amaranth on September 28, 2012, 02:11:24 PM
I've run into a situation where I need to set the Target FSM field in the UIEventsToPlaymakerFSM, using a NGUI script called UIPopupList.

I'm not sure how to get pmEvents.targetFSM to get the game object that has the FSM. I tried using this code to reference the game object, but I get a conversion error, since targetFSM is looking for an FSM component:
var otherGameObject = GameObject.Find("Other");

Anyone know a solution? I'm trying to reference a game object in the Hierarchy called Monitor that contains an FSM called Click.

Code: [Select]
UIEventsToPlaymakerFSM pmEvents = UIEventsToPlaymakerFSM.Get(lbl.gameObject); //works
pmEvents.onClickEvent = "Item Clicked";  //works
pmEvents.targetFSM = //What goes here?
Title: Re: set Target FSM via script (UIEventsToPlaymakerFSM)
Post by: jeanfabre on October 01, 2012, 01:29:33 AM
Hi,

 never played with that, but the target Fsm is likely a reference to the PlayMaker Component itself-

 Fsm are components attached to a gameObject like any other components in Unity.

bye,

 Jean
Title: Re: set Target FSM via script (UIEventsToPlaymakerFSM)
Post by: amaranth on October 01, 2012, 03:57:06 PM
Woot, it worked!!!

Added this to NGUI's UIPopupList.cs:
Code: [Select]
// playmaker event listener
var go = GameObject.Find("Click Monitor");
PlayMakerFSM fsmComponent;
fsmComponent = go.GetComponent<PlayMakerFSM>();

UIEventsToPlaymakerFSM pmEvents = UIEventsToPlaymakerFSM.Get(lbl.gameObject);
pmEvents.onClickEvent = "Item Clicked";
pmEvents.targetFSM = fsmComponent;