playMaker

Author Topic: Making A Reusable State  (Read 422 times)

Arzola

  • Playmaker Newbie
  • *
  • Posts: 1
Making A Reusable State
« on: November 04, 2021, 09:48:48 PM »
Good day,

I'm currently dealing with a state machine that uses identical states on different sections of a FSM. This state is identical, as it's basically just a routine operation that references different scripts, that I want to execute whenever it goes through a specific path, or as part of some global transition paths.

And my issue is that having several copies of this state is very error prone, as you have to be very careful to ensure that all states are exactly the same, and that you don't miss any of them when "updating".

And I know that I have the option to just keep this as a single state with no copies, and then set flags that can help me return to wherever this state was called from. But I believe that can become a tangled mess really quickly if I wanted to call this from several spots, where setting up the flags is another area where errors can happen.

So I thought I could instead make this an unreachable state, and with the help of a custom action, I could trigger the "OnEnter()" method of all its actions. This approach actually works very well. By using the unique state name, I can find the target state, cache it, run its OnEnter() methods (active only if I so desire), and execute Finish().

And while this minimizes potential errors by a lot (as the only thing I can get wrong now is the state name), I'd still prefer to keep the potential error count to 0.

And this is the part I need help with, is there a non-user editable identifier for a state? or is the state name the only unique identifier?
« Last Edit: November 04, 2021, 09:51:03 PM by Arzola »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7623
    • jinxtergames
Re: Making A Reusable State
« Reply #1 on: November 05, 2021, 09:02:18 AM »
Hi.
Maybe use a 'Run Fsm' action with a FSM Template?

Here's a video on how Run Fsms work :