playMaker

Author Topic: In what order are FSMs run, or, what has priority over what?  (Read 3172 times)

Mupp

  • Full Member
  • ***
  • Posts: 167
In what order are FSMs run, or, what has priority over what?
« on: November 27, 2019, 06:20:27 PM »
I have 2 FSMs on the same object. One moves the object with SetPosition when I press buttons. The other shoots Raycasts to check if the object hits walls. If it hits, it moves the object so it no longer clips the wall. It also uses SetPosition. This is set to happen once every frame for both FSMs.

So what happens if the object hits a wall and I keep pressing the button, which of the 2 FSMs have priority? Both, apparently..?

What happens is the object stops moving at the wall but it still clips into it the same distance it should have moved that frame. When I release the button, the object moves so it no longer is clipping.
So it looks like both FSMs happens but shouldn't the one with the Raycasts happen later since Raycasts takes longer to do and overwrite the position from first FSM? Changing the order of the FSMs components on the object does nothing.

So I wonder what can I do to make sure one FSM has priority over an other?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: In what order are FSMs run, or, what has priority over what?
« Reply #1 on: November 29, 2019, 08:57:38 AM »
Hi,

 short answer: you can't :)

I would tend to think they are executed in order in the component stack, but I would not bet on that at all.

instead, do this:

-- move the object during regular update
-- raycast during late update

this is better because late update will guarantee no object will be moved for this update, and so you are sure about the sequence.

If the raycast action you want to use doesn't have the late update option, let me know I'll add it. that will be probably needed in your case.

check out the ecosystem, it has for example RaycastAdvanced which does provide access to the lateupdate cycle.


Bye,

 Jean

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: In what order are FSMs run, or, what has priority over what?
« Reply #2 on: November 29, 2019, 12:08:04 PM »
Hi,

 short answer: you can't :)

I would tend to think they are executed in order in the component stack, but I would not bet on that at all.

Thanks, it's always good to know what's going on under the hood.

I tried RaycastAdvanced, but it doesn't work at all. It does not even shoot a ray so I could not test it.

I also tried to change SetPosition to late update for the wall check, but that didn't do anything. I even tried to disable the collision FSM and only ran it when the movement FSM was done withe its loop, but that didn't change anything either.

I mean I can fix this by disabling movement when you hit a wall, but I really want to know what's actually happening.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: In what order are FSMs run, or, what has priority over what?
« Reply #3 on: December 02, 2019, 03:07:05 AM »
Ok,

 I am trying to make sense of what you are trying to achieve, but I am not sure really. why not using simple Colliders to prevent players passing through walls and using simple collision detection to be aware of when a player touches a wall? you could also create a trigger slightly bigger than the collider and use that trigger to know in advance that a a wall is near the player.

Bye,

 Jean

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: In what order are FSMs run, or, what has priority over what?
« Reply #4 on: December 02, 2019, 03:43:04 PM »
Ok,

 I am trying to make sense of what you are trying to achieve, but I am not sure really. why not using simple Colliders to prevent players passing through walls and using simple collision detection to be aware of when a player touches a wall?

Because from trying to do it like that I have gotten horrible results. Collision is extremely inconsistent, sometimes it takes several frames to block and push you out of the wall.
An other example is how you can get different collisions depending on which side you hit. On one side you might clip into the wall and if you jump up you might land on the top of the collider even if you should be to the side of it. Sometimes you might slide along a collider and just randomly get stuck.
All this seems to happen differently depending on your current frame rate, or change if you restart the editor or which day it might be. Maybe the weather too...
I'm using 5.6 so it's perhaps better in newer version but with my method I'm at least in full control of the objects positions at all times.

But that is not what this thread is about. I just wanted to know how I can make FSMs run in a certain order.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: In what order are FSMs run, or, what has priority over what?
« Reply #5 on: December 03, 2019, 03:28:08 AM »
Hi,

 ok, so you can't control fsm order of execution, the only way to impose that is to have a sequence of state and actions, that you can have control over, so within he same fsm, the actions and state will obey the order in which they are designed, stacked up and how event flows between states.

Bye,

 Jean

Mupp

  • Full Member
  • ***
  • Posts: 167
Re: In what order are FSMs run, or, what has priority over what?
« Reply #6 on: December 03, 2019, 09:06:35 AM »
Ok, I see. Thanks.