Playmaker Forum

PlayMaker News => General Discussion => Topic started by: BigDog on May 30, 2015, 07:15:03 PM

Title: Send Event to Sub FSM from script[SOLVED]
Post by: BigDog on May 30, 2015, 07:15:03 PM
In my effect to practice good software engineering, I am trying to use "Run FSM" more. But I have come to a roadblock. I can't send event directly to the 'sub FSM'.

Before I used 'sub FSM', I have a state waiting on a event which gets send from C# script. Now this state is moved into the template. And it no longer received the event. How can I get send a event to a sub fsm?

Thanks
Title: Re: Send Event to Sub FSM from script
Post by: BigDog on May 30, 2015, 07:41:01 PM
Hi, I just solved my own problem.

The trick is to use the obscure FSM property of the fsm.

Code: [Select]
HutongGames.PlayMaker.FsmEventTarget etarget = new HutongGames.PlayMaker.FsmEventTarget();
etarget.target = HutongGames.PlayMaker.FsmEventTarget.EventTarget.SubFSMs;

m_MovementFSM.Fsm.Event(etarget, "arrived");

Thanks.
Title: Re: Send Event to Sub FSM from script
Post by: jeanfabre on June 03, 2015, 03:49:12 AM
Hi,

 You have two entry point, PlayMakerFSM and FSM, PlayMakerFSM is the component itself ( that is dropped onto the GameObject), while the FSM is the actual class representing the fsm ( the visual canvas).

and so PlayMakerFSM compose some of the methods of FSM but no all. hence why some of the stuff is done via .Fsm

 Bye,

 Jean
Title: Re: Send Event to Sub FSM from script
Post by: BigDog on June 26, 2015, 06:10:50 PM
I come across another issue with sending event to sub fsm. The issue is it doesn't work after one level of sub fsm. Is this by design or is this a bug? This makes the template system very limiting.

Thanks
Title: Re: Send Event to Sub FSM from script
Post by: BigDog on June 26, 2015, 06:33:53 PM
I eventually managed send event to second level sub fsm from script. The trick is to set the events to global event, which I needn't had to do with the first level sub fsm.

Thanks
Title: Re: Send Event to Sub FSM from script
Post by: Alex Chouls on June 26, 2015, 09:25:27 PM
You can access sub FSMs directly using this property of Fsm:
public List<Fsm> SubFsmList

Then you can call Event(string eventName) or Event(FsmEvent event) on the sub FSM directly.

Title: Re: Send Event to Sub FSM from script
Post by: BigDog on June 27, 2015, 07:28:12 PM
Great! That's what I need. Thanks!