playMaker

Author Topic: Why (and when) would you use Multiple FSMs on a GameObject.  (Read 6225 times)

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
    • Out to Play Interactive
Why (and when) would you use Multiple FSMs on a GameObject.
« on: August 17, 2012, 08:58:31 AM »
I'm trying to digest more complex concepts in PlayMaker recently but this still eludes me.  When might you use a second (or third), FSM on an object.  Could someone suggest a relatively simple example of when this would be useful?

thanks,
B.

Uttpd

  • Junior Playmaker
  • **
  • Posts: 67
    • View Profile
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #1 on: August 17, 2012, 12:22:07 PM »
In any situation you want the Game Object to perform more than one thing at the same time, independently.






brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #2 on: August 17, 2012, 01:43:18 PM »
Appreciate the input, but that is a bit broad.

A single FSM could trigger an object to move, while changing GUI Text, while updating the texture on a specified game object and playing a sound. Granted in sequence. 

Under what circumstances would two (or more), FSMs bet better than one?

Uttpd

  • Junior Playmaker
  • **
  • Posts: 67
    • View Profile
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #3 on: August 18, 2012, 09:45:33 AM »
ok;
Lets say you have a cube that moves from A --> B--> C
And you want the cube to change color depending on Time.

you could make it all in one FSM, but then you would have to make a Time Check/ color change in every sate the cube could be in a given time (A, B, C) and for every color
Instead you use a second FSM to take care of the Color/Time in one simple state.

Now you want the cube to jump x meters when its on B and the color is yellow and y meters when is blue
So make another FSM that checks the other ones states...

Now imagine doing it on a single FSM!. Every state on that FSM would have to check move time color jump..

PS: In your example as you say all the actions are in sequence and that works perfectly in on single FSM. Is when you add interactivity that a single FSM wont do.
« Last Edit: August 18, 2012, 09:49:26 AM by Uttpd »

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #4 on: August 18, 2012, 08:38:57 PM »
Terrific reply.  Makes perfect sense now.  I appreciate you going a bit deeper to clear this up. Hopefully it will be equally helpful to some other artsy type like myself.


Have a great weekend

B>

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #5 on: August 18, 2012, 11:20:12 PM »
I use separate FSM's heavily on character control setups.

Such as having an FSM for handling mouse inputs, then another FSM for handling the movement transformations. Basically you need it because if your FSM is handling an input like firing or something then thats all its doing. If you want it to do anything else you have to interrupt it and stop doing that action and also on each state have it check for outside input probably which all sums up to be very bad.

Separating things by FSM lets it run more states simultaneously, whereas trying to do it all on a single FSM if that is possible will often be too complicated and expensive and more difficult to maintain.

Netjera

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #6 on: August 19, 2012, 11:05:08 AM »
Is this sort of approach more useful than having independent controller objects for each type of thing?

(Thanks a lot for asking this!  This may solve a problem I'm having putting together an inventory panel!)

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #7 on: August 19, 2012, 02:52:40 PM »
Thanks for the practical example, Lane.  That really helps understand how this type of setup can me advantageous.  I had the same thoughts on Global transitions too. I know how to implement, but was wondering when and to what great advantage they can be. Running through the example files yesterday (that used to be bundled with Playmaker...) I found a nice mix of examples.  I think they could stand a bit of updating, or addition as there are more functions available now.

But between the videos, the docs the examples and the community on this forum, Playmaker is by far the best supported and resourced tool available for Unity scripting (or anything else for that matter).

B

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #8 on: August 19, 2012, 03:50:34 PM »
Is this sort of approach more useful than having independent controller objects for each type of thing?

(Thanks a lot for asking this!  This may solve a problem I'm having putting together an inventory panel!)

You could do it either way, if it works then its just a matter of whether you want to localize it to that object or use another manager object for that action. Really depends on what you're trying to do.

If you guys want some more examples you're welcome to look at this little top down space scene i put together. I highly doubt I've chosen all of the best ways to do these things as I'm still learning that as well but might give you some ideas. 100% of the gameplay and interaction is flowing through Playmaker.

https://dl.dropbox.com/u/38606641/AngryShips/AngryShips.unitypackage
Edit: You'll need to re import the two DLL's that come with Playmaker in order for it to work.
« Last Edit: August 19, 2012, 03:53:06 PM by Lane »

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • View Profile
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #9 on: August 19, 2012, 05:56:41 PM »
Lane... really appreciate the share, man.   I am lookin' forward to checking it out.  As I start coming up with interesting scenes using Playmaker, I will be glad to post em.  Be great if we had a section where we could post such stuff.  Sharing the knowledge is by far the quickest way for folks to get good and potentially find other devs that may wish to team up on larger projects.


Thanks again,
Brendan

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #10 on: August 20, 2012, 12:32:34 AM »
Hi,

 When you want to share something, simply drop me a line, and I'll add it to the user wiki ( else you can ask Alex to be a member of the user wiki). I'll happily organize the project you are sharing with the community.

bye,

 Jean

Netjera

  • Playmaker Newbie
  • *
  • Posts: 41
    • View Profile
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #11 on: August 20, 2012, 10:58:20 AM »
Is this sort of approach more useful than having independent controller objects for each type of thing?

(Thanks a lot for asking this!  This may solve a problem I'm having putting together an inventory panel!)

You could do it either way, if it works then its just a matter of whether you want to localize it to that object or use another manager object for that action. Really depends on what you're trying to do.

If you guys want some more examples you're welcome to look at this little top down space scene i put together. I highly doubt I've chosen all of the best ways to do these things as I'm still learning that as well but might give you some ideas. 100% of the gameplay and interaction is flowing through Playmaker.

https://dl.dropbox.com/u/38606641/AngryShips/AngryShips.unitypackage
Edit: You'll need to re import the two DLL's that come with Playmaker in order for it to work.

Thanks!  I guess I'm wondering about best practices.  Jean recently made a mouse tooltip action he shared with me, and I noticed that he included the variable as a local variable exposed in the inspector.  I've been having a lot of trouble using a local variable approach, and had been making everything into bigger FSMs.  I'd much prefer to really localize and segment what's going on, but I wasn't sure what was the most efficient.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14703
  • Official Playmaker Support
    • View Profile
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #12 on: August 20, 2012, 12:56:08 PM »
Hi,

 Divide and conquer is the best approach when you are not sure. You can always refactor and optimize later. If you build a big fsm, then refactoring is a pain. Do lots of small Fsm, you'll then quickly gain experience while being productive and then have a better initial brainstorming as you go. If you build a big fsm, you will always be in the blur.

bye,

Jean