playMaker

Author Topic: Shared FSM between Unity Object  (Read 3857 times)

mochatony

  • Playmaker Newbie
  • *
  • Posts: 7
Shared FSM between Unity Object
« on: December 11, 2013, 08:29:26 AM »
Hello

Would like to know is it possible to have shared FSM between unity objects. Consider following scenario where I have a group of button that will load different level, those level require pay to unlock. As such they shared same FSM logic, the different might only be the level to load, possibly variable pass by string.

I understand there's custom template where I can save and load, but considering I update the FSM logic in future, I would need to update each button manually (reload and update url), which would be troublesome.

Would like to know is there's something like share FSM logic between components.

Thank you

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Shared FSM between Unity Object
« Reply #1 on: December 11, 2013, 12:13:04 PM »
Would like to know is it possible to have shared FSM between unity objects.

A gameobject can have multiple FSM's, but a FSM has always just one internal "owner".

Quote
Consider following scenario where I have a group of button that will load different level, those level require pay to unlock. As such they shared same FSM logic, the different might only be the level to load, possibly variable pass by string.

That has nothing directly to-do with playmaker or a FSM, but is solved by using unity prefabs. In addition u can use fsm templates in conjunction with prefabs, but its optional. U setup your FSM and expose all user setable data via inspector variables from the FSM. Than u create your prefab and instantiate it how often u like. Now u edit the inspector variables to your liking. If u change the FSM or prefab any none changed property will be automatically updated for all instances, so u don't need to manually update each instance.

Quote
Would like to know is there's something like share FSM logic between components.

By using events, variables and references in conjunction with a FSM u basically always use "share FSM logic".


bye Andy

PS: Its really hard to understand what u want to-do without a more concrete example.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Shared FSM between Unity Object
« Reply #2 on: December 11, 2013, 02:53:59 PM »
Hi,

 There are two mecahism for this:

-- Templates
-- Sub Fsms.

 Sub Fsm will allow you to reuse the same logic within a Fsm, several times per fsm, or per state, so very powerful indeed.
Templates are really for reusability at a fsm level, so you can simply refer to a template, within the playmaker component inspector ( not by pasting a template, that would not be reusable, it would simply be like a snippet you copy paste for convenience).

 I find templates extremly powerful indeed, simply because it allows me to NOT use prefabs, and yet, reuse logic! say you have so mayn different objects that needs a specific behavior ( let say collectables), with just prefabs, its impossible to write one prefab that fits all collectables, that would be really bad, and so you are having maybe 5 or 10 prefabs for each main types of collectables, yet, you want a reusable piece of code, for example, it's point number computation logic, make it as a template and simply reference that template on all ten prefabs. there you go, you hav extremly powerful reusability, and Unity prefabs remains manageables.

Bye,

 Jean

bye,

 Jean

Andy22

  • Junior Playmaker
  • **
  • Posts: 99
Re: Shared FSM between Unity Object
« Reply #3 on: December 12, 2013, 04:22:31 AM »
Sub Fsm will allow you to reuse the same logic within a Fsm, several times per fsm, or per state, so very powerful indeed.

Good point, did forget about those, since they are a little hidden inside the "Run FSM" action.

Btw something for the wish-list, would be nice to have the template field inside the "Run FSM" action work as a variable, that can be exposed to the inspector. So u can directly select what template to use. U could also add some folder/category specific filter option to this, so u could only allow templates from a certain folder to-be selected. This way u could actually create one collectible prefab, that changes behavior by selecting the correct "type" template. Ofc using a filter u make sure only certain templates are use-able in this FSM prefab.


bye Andy