playMaker

Author Topic: Order of multiple FSMs in a GameObject  (Read 851 times)

protozerg

  • Playmaker Newbie
  • *
  • Posts: 7
Order of multiple FSMs in a GameObject
« on: February 06, 2021, 09:39:23 PM »
Hi,

I put three different FSMs as 'Play Maker FSM' components in one GameObject, but the order in which the START states of the three FSMs are called is different in the editor or builds.
Can we prioritize calling multiple FSMs in an object?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Order of multiple FSMs in a GameObject
« Reply #1 on: February 06, 2021, 10:05:16 PM »
Unfortunately, the update order of components in Unity is not guaranteed. If it's important that some FSMs update in a specific order, you have to do it explicitly.

For example:

The FSM that should run first can send an event to the FSM that runs second. The second FSM waits for this event before doing anything that depends on the first FSM running.

Or the first FSM can enable the second FSM.

Does that make sense?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 773
Re: Order of multiple FSMs in a GameObject
« Reply #2 on: February 07, 2021, 12:35:24 PM »
First thing to do, if you have several FSMs on a GO, number them. In most cases in PM, this numbered listing will always show the FSMs as you listed them (1, 2, 3, etc.).
Second thing, it is important to know that the FIRST FSM created on a GO is remembered as 1st by Unity. This is important because Unity sends events to the 1st FSM only if you use Unity components to communicate with FSMs, or in other words, have elements external to Playmaker send messages to Playmaker's FSMs.
Playmaker does not have such issues since it's internally built to be able to see several FSMs on a single GO and communicate with any of them, in group or one by one, targeted, but Unity is built according to the idea of one type of component only per GO.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Order of multiple FSMs in a GameObject
« Reply #3 on: February 09, 2021, 04:14:56 PM »
Hi
Quote
but Unity is built according to the idea of one type of component only per GO.

That said (just thinking out loud) maybe an idea would be to have a 'Mother' Fsm component where you can add fsm's within it.
a bit like placing multiple templates.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 773
Re: Order of multiple FSMs in a GameObject
« Reply #4 on: February 11, 2021, 04:40:19 AM »
Yup, some kind of megaproxy.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Order of multiple FSMs in a GameObject
« Reply #5 on: February 11, 2021, 10:30:55 AM »
Yeah, that's an interesting idea.