playMaker

Author Topic: Fully Nestable SubFSM Communication  (Read 8777 times)

HardLight680

  • Playmaker Newbie
  • *
  • Posts: 2
Fully Nestable SubFSM Communication
« on: May 07, 2018, 05:03:48 PM »
I made up a small action that allows you to run FSM templates and return data back to the caller regardless of whether the caller is a sub FSM or a host FSM. It is entirely self-contained, so there is no need to use additional actions besides the one RunFSMFunc action. There is no need for any special actions inside the sub FSM either.



The operating principles are similar to the RunFSM action. Variables with the Inspector attribute will appear as inputs, and the sub FSM may terminate using the FinishFSM action.

As a new addition, variables in the template that are inside the 'Output' category will appear as outputs which can be captured into variables for the calling FSM. Output variables are automatically copied by value up into the calling FSM's capture variables when the sub FSM ends without the need for any special actions.

Additionally, string variables in the template that are inside the 'Events' category will generate event selection fields on the action. The template FSM can use those string variables in SendFSMByName with the HostFSM target type in order to send caller specified events back to the caller.

Note that if the calling state ends while a sub FSM is still running, the sub FSM is immediately ended and its current output values are copied to the calling FSM. As a result, if a sub FSM output event causes a state transition in the caller, the sub FSM ends and its current computed values are copied out.

The package contains samples for Factorial and MergeSort FSM templates to show the basics of how it is used, and to show how this can be used for recursive FSM programming.

2018/05/08: Updated to support FSM event outputs.


* PlaymakerRunFsmFunc.unitypackage
« Last Edit: May 09, 2018, 02:11:34 AM by HardLight680 »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Fully Nestable SubFSM Communication
« Reply #1 on: May 07, 2018, 05:48:19 PM »
Very cool! This is very similar to an approach I've been playing with to improve the RunFSM action. I love the use of a category to define the outputs - very clever! Thanks for sharing - will give it a go :)

I'd also like sub FSMs to be able to send events to the parent FSM. So a template really can work just like an action. But have been struggling with a design for this - do you have any ideas :)

HardLight680

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Fully Nestable SubFSM Communication
« Reply #2 on: May 08, 2018, 12:22:29 AM »
I never really thought about doing events, but a straightforward solution might be to expose a category of string variables - such as 'Events' - and use those to specify the caller's preferred event triggers.

You would need to use some inspector magic to make sure that the exposed event controls are interpreted as FSMEvent variables instead of FSMString variables, but still get translated properly as string names. Inside the template itself, you could then use SendEventByName with the HostFSM target to send these events back up to the caller.

It looks like specifying HostFSM as the target will send the event up to the most immediate caller, so you don't need to worry about accidentally skipping levels or anything. It also bypasses the need for the events to be marked as Global, so this should work pretty well for keeping things self contained.

The only other thing that might be nice to have would be a FinishFSM variant that allows you to send an event up to the caller and end the FSM at the same time.

Most of this seems pretty straightforward, so I'll see if I can add it to this action.

Edit:

I have updated the package to include the above feature. I did not add the FinishFSM variant as causing a state transition in the caller now automatically causes the sub FSM to terminate. However, since the caller is not guaranteed to respond to events sent from the sub FSM, there may still be certain edge cases where an action like this would be convenient.

So far, it seems relatively stable. There might be a minor issue with cluttering up your string variables with event holders, but it shouldn't be too bad as long as you don't go crazy.

There is also a minor issue in that adding a SendEventByName action to a sub FSM while you are in the nested FSM editor window will cause an exception in the UI. This can be avoided fairly easily if you modify the template directly by clicking on the asset as opposed to clicking on the Edit button inside the action.
« Last Edit: May 08, 2018, 04:38:48 AM by HardLight680 »

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 234
    • Haven Made
Re: Fully Nestable SubFSM Communication
« Reply #3 on: August 15, 2018, 10:56:29 PM »
This is incredible! :D

Just started using it and its been super stable. Really a great iteration on the Run FSM action/workflow.

Alex can you change HardLight's forum title to a Hero Member? ;)

-craigz


Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Fully Nestable SubFSM Communication
« Reply #4 on: August 16, 2018, 03:25:02 AM »
I never fiddled around too much with templates and sub fsms, so let's get this straight.

I have a template which is saved as an asset and by using Run FSM Func i can run that template to do stuff based on input, and then return the result as an output, which is cool since i don't need to have actually have an FSM on the game object, just the one to call Run FSM Func if i'm doing it without code.

But how do we define input and output? Some boilerplate code would be cool.

When i look at this, the possibilities it offers are huge!
« Last Edit: August 30, 2018, 01:40:30 PM by krmko »
Available for Playmaker work

TwisterK

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Fully Nestable SubFSM Communication
« Reply #5 on: September 20, 2018, 01:50:06 AM »
This is awesome, it will make FSM template solution far more complete with this action. Thanks for sharing!

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 234
    • Haven Made
Re: Fully Nestable SubFSM Communication
« Reply #6 on: July 02, 2019, 05:35:41 PM »
I just want to add visibility to this chain again. It's been so invaluable these past few years :)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Fully Nestable SubFSM Communication
« Reply #7 on: July 03, 2019, 07:59:18 PM »
hi.
@craigz

There is already a new version to try on the PM beta version :D

You can ask Alex or Jean for beta access.

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 234
    • Haven Made
Re: Fully Nestable SubFSM Communication
« Reply #8 on: July 04, 2019, 01:51:41 AM »
I am in the beta already! :D though I was not aware it was integrated into beta yet.

Do you know if there is any reasonable upgrade path for if I'm heavily using this integration? Or is it a matter of just starting to use the official one? :P

-craigz

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Fully Nestable SubFSM Communication
« Reply #9 on: July 04, 2019, 03:35:03 AM »
Hi.
I did not mean a new version of the action posted here, but a new version of runfsm :)
So they will be 2 different ones (just to be clear)

I think you can use the action aside to the one on this post, but i can not confirm that.

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 234
    • Haven Made
Re: Fully Nestable SubFSM Communication
« Reply #10 on: July 05, 2019, 02:28:27 AM »
Right, sorry, that is how I interpreted it as well :)

So it would just be a matter of using the run fsm template action instead of this current one 👍

Thanks for the clarification Djaydino!
-craigz

Marc Saubion

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Re: Fully Nestable SubFSM Communication
« Reply #11 on: November 20, 2019, 09:51:23 AM »
Hi.
I did not mean a new version of the action posted here, but a new version of runfsm :)
So they will be 2 different ones (just to be clear)

I think you can use the action aside to the one on this post, but i can not confirm that.

Hi

I just started using the beta because I'm very interested in that feature (input outpud on run fsm) but I can't find it.

Is it still around?
Do you guys have some documentation about it?

Thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Fully Nestable SubFSM Communication
« Reply #12 on: November 24, 2019, 08:47:58 PM »
Hi,
@ Marc

It is available on PlayMaker Beta.

If you wish to participate in beta you can contact Jean or Alex.

puddlepouncer

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Fully Nestable SubFSM Communication
« Reply #13 on: April 03, 2020, 02:19:06 PM »
When I use the Run FSM function action I keep getting "You are editing the FSM while the game is playing" error. I read there are some issues in how you open and edit the templates but I can't seem to get around this issues.

Maybe I'm doing something illegal within the template to cause this? Any ideas where the error might lie?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Fully Nestable SubFSM Communication
« Reply #14 on: April 14, 2020, 01:56:26 AM »
Hi,

 what version of Unity are you using?

Bye,

 Jean