PlayMaker Updates & Downloads > Share New Actions

Fully Nestable SubFSM Communication

(1/4) > >>

HardLight680:
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

Alex Chouls:
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:
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.

craigz:
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:
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!

Navigation

[0] Message Index

[#] Next page

Go to full version