playMaker

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

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • Out to Play Interactive
Why (and when) would you use Multiple FSMs on a GameObject.
« on: August 17, 2012, 11: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: 70
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #1 on: August 17, 2012, 03: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
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #2 on: August 17, 2012, 04: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: 70
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #3 on: August 18, 2012, 12:45:33 PM »
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, 12:49:26 PM by Uttpd »

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #4 on: August 18, 2012, 11: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: 2511
  • Mender of the past
    • Cleverous
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #5 on: August 19, 2012, 02:20:12 AM »
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.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Netjera

  • Playmaker Newbie
  • *
  • Posts: 41
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #6 on: August 19, 2012, 02:05:08 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!)

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #7 on: August 19, 2012, 05: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: 2511
  • Mender of the past
    • Cleverous
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #8 on: August 19, 2012, 06: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, 06:53:06 PM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

brendang

  • Junior Playmaker
  • **
  • Posts: 63
    • Out to Play Interactive
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #9 on: August 19, 2012, 08: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: 15500
  • Official Playmaker Support
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #10 on: August 20, 2012, 03: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
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #11 on: August 20, 2012, 01:58:20 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.

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: 15500
  • Official Playmaker Support
Re: Why (and when) would you use Multiple FSMs on a GameObject.
« Reply #12 on: August 20, 2012, 03: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