playMaker

Author Topic: How does multiple FSM run?  (Read 2531 times)

tester

  • Playmaker Newbie
  • *
  • Posts: 31
How does multiple FSM run?
« on: September 09, 2012, 04:46:25 AM »
Since I think FSM doesnt use multiple thread or multiple cpu, I wonder how FSM runs.
First assume there is no thread yield, or no UI pause.
 
1) How do they determine which FSM start first? and when should the other FSM start?
2) Lets say if i have a infinite loop in 1 FSM, does all the FSM pause.
3) Does FSM run like Javascript (not unityscript)
4) Lets say if i send event from FSM-A to another FSM-B, does FSM-A wait until FSM-B finish process first.

Red

  • Hero Member
  • *****
  • Posts: 563
Re: How does multiple FSM run?
« Reply #1 on: September 09, 2012, 06:53:45 PM »
1) That one i don't fully know. I would assume (correct me if i'm wrong) that it'd execute in descending order... so, if you have three FSMs on one object, the first will fire first, second second... etc... but the time it takes to fire them all off is likely imperceptible to human eyes but if you're concerned about that and want to make sure that your actions have enough time to do the things that you want them to do, what i've done is in the start state (if it's waiting for another action such as my "player setup" system which defines the models, weapons and statistics of the player character) put in a "Wait" and set it to something small like 0.1 seconds. and if you're concerned that a state is transitioning too fast, you can put in a "next frame event" action at the end and tell it to trigger the transition state on completion... this one is tricky though because if your state has a lot of beefy actions to process, it might sometimes fire off too soon for those actions to complete (such as if you're getting and setting a lot of other FSM system variables with the "Get/Set FSM Variable" actions as i've noticed that they are pretty beefy.)

2) as far as i am aware, an infinite loop will not make the other FSM's pause... though Playmaker does have some infinite loop detection that will cut one out after a certain number of loops, it won't trigger in all cases (so, if you have it doing something while it's in the infinite loop, it'll keep triggering and suck down all your CPU resources in the process.)

3) This one i don't feel i'm qualified to really answer... though most (if not all) the actions are in C#, but that's about all i do know.

4) as far as i've been able to determine, if A is sending the event, as soon as it's sent it'll go on to the next action... but B will click over as soon as it recieves the appropriate event, regardless as to state it's in or what action it's performing... i think this is because most FSMs are essentially running independently of one-another.

as for the UI pause, there isn't one built in per-se but you can use the timescale actions ("Scale Time" in the "time" subsection of the action browser) to essentially pause your game by reducing the time to 0.