playMaker

Author Topic: FSM ordering issues  (Read 1460 times)

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
FSM ordering issues
« on: September 18, 2020, 04:47:39 AM »
Hi,

I have a question regarding ordering. Is there a "correct/better" way to make sure that some FSM do their start-state first?

In my game there are some GameObjects ("A") that use "get owner" and save themselves in a variable in the start state. And then there are some other GameObjects ("B") that need to find and use that variable.

I find it that sometimes B can't find A. It's like the start state of the FSM happens in the first frame of the game, and depending on the processor and what loads first it sometimes work and sometimes don't.

Right now I solve this with B having a "Wait 0.1 sec" (or use Next frame event) in its start state and then goes to a second state that gets the variable from A. Even if this works it doesn't feel right, there should be a better (more consistent) way of doing so.

Anyone have any input?


600

  • Moderator
  • Hero Member
  • *****
  • Posts: 715
    • Flashing Lights
Re: FSM ordering issues
« Reply #1 on: September 18, 2020, 05:15:55 AM »
Can not rely on which goes first that way or even Wait might be different on builds/devices.
I have first states to get all needed and then set it's "setup" bool to true, so other FSMs waits for it and then continue.

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: FSM ordering issues
« Reply #2 on: September 18, 2020, 06:11:51 AM »
I thought that the idea of "next frame event" was that it ensured that it changed state on the next frame (independently of the time it took).

If I should add a "setup-bool" after each start start state it would take a lot of extra work and a lot of extra states. There must be a better way to handle this vital part. How does people with bigger project handle this?

600

  • Moderator
  • Hero Member
  • *****
  • Posts: 715
    • Flashing Lights
Re: FSM ordering issues
« Reply #3 on: September 18, 2020, 06:59:10 AM »
Yeah I haven't found better way. When get used to it it makes sense, even can have separate setup FSM that gets all and others takes from there. It really doesnt add that much.
Also there is option to wait for certain State name or Setup fsm send out global events, but those are harder to control and edit if needed.
For my game there is one root gameobject that acts as master Setup and deals with most of scene objects and settings where later any prefab or scene object can take desired object/value.
Next frame event is great and used a lot to wait for objects/values to load until next frame, but would not recommend using for such setups because of same issue like Wait actions, that can actually not match in later versions of your game nad end up looking for weird bugs in future.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: FSM ordering issues
« Reply #4 on: September 18, 2020, 10:01:50 AM »
Hi.
Depending on what you are doing in that frame, its possible not everything is done in that frame.

If a object does not need to setup things and only needs to do 'Get Owner' and place in a global, you can also use 'Game Object Is Null' to check.

Even in C# coding you need this type of checking.

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: FSM ordering issues
« Reply #5 on: October 13, 2020, 04:03:26 AM »
Hi.
Depending on what you are doing in that frame, its possible not everything is done in that frame.

If a object does not need to setup things and only needs to do 'Get Owner' and place in a global, you can also use 'Game Object Is Null' to check.

Even in C# coding you need this type of checking.

Hi!
Thanks for the reply, I now have a state that checks "is null" in these scenarios and it is working fine. However...

... the main issue still kinda remains, how do I ensure that some actions/states are run in a particular ordet. For instance: I have a simple state that, on activation, checks if a gameobject is within a triggerbox. This is handled with a On trigger Stay. If the object is NOT in the trigger box, it should proceed to the next state in the fsm.

I have fixed this with a Next frame event that is run directly after the On trigger stay. This works in like 50% of the time. I guess the issue is that On trigger Stay is not always managed to run on the exat first frame (due to computeing and calculations?) and the Next frame event runs before and the FSM proceeds to the wrong state.

So: How do I ensure that the the ordering is correct? How is stuff like this managed in C#? I know that there is a "Late Update" that could be used for stuff like this, but not all actions have this option and the issue would be there as well, what happens if a lot of stuff happens in Late Update, what would be executed first?

Right now the best way I found is the use a Wait for like 0.3 sec, but this feels very unreliable and clunky way of programming.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: FSM ordering issues
« Reply #6 on: October 13, 2020, 05:26:53 AM »
Hi.
I use a Template fsm that has 2 states.

each state have a bool (inTrigger)
and a Trigger(2D) event

start state :

Set Bool Value (False)
On Trigger Event (enter)

state 2

Set Bool Value (True)
On Trigger Event (Exit)


Then on other fsms i can use Fsm Bool Test (Ecosystem)
to check in in trigger or not.

Krillan87

  • Beta Group
  • Full Member
  • *
  • Posts: 185
Re: FSM ordering issues
« Reply #7 on: October 13, 2020, 09:29:07 AM »
Hi.
I use a Template fsm that has 2 states.

each state have a bool (inTrigger)
and a Trigger(2D) event

start state :

Set Bool Value (False)
On Trigger Event (enter)

state 2

Set Bool Value (True)
On Trigger Event (Exit)


Then on other fsms i can use Fsm Bool Test (Ecosystem)
to check in in trigger or not.

Hi!

I see... maybe I should look into something similar. Thanks for the help!