0
Fixed

Order of operations bug

NeedsLoomis 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 6

This one has thrown a big wrench in my project, if anyone else is seeing the same thing, let me know.

It appears that Bolt is doing things in an unintuitive order.  I would assume states are supposed to execute as:

  1. On Enter State
  2. Update State
  3. On Exit State
  4. Transition
  5. On Enter State (second state in the chain)

But instead it seems to go 1 > 4 > 3 > 5 > 2

Pic and link to a simple scene (just the scene and the script, install bolt first) below.


https://www.dropbox.com/s/dzal1tfnqd9ue99/BoltOrderBug.unitypackage?dl=0

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Sorry, jumbled up the numbers in my original example.


+1
Pending Review

Hi NeedsLoomis,

Thanks for the bug report. Here's what's happening (or should be!) under the scenes when a state is entered:

  1. Start listening to all events on the outgoing state transitions
    This needs to happen first in case you trigger an event from On Enter State that should transition.
    You made me realize the need for this change with your bug report here:
    http://support.ludiq.io/topics/261-event-timing-issue/
  2. Trigger On State Enter in the source state
  3. Trigger Update in the source state
  4. Trigger Update in each outgoing transition

    Then, if a transition is triggered:
  5. Trigger On Exit State in the source state
  6. Stop listening to all events in the source state
  7. Stop listening to all events in the outgoing transitions
  8. Repeat at #1 for for the destination state

What I think is going wrong here is the order of Update. It seems that #3 and #4 in my list are not always predictable, and #4 might trigger before #3, which could be the root cause of your issue.

To be clear however, in your initial list, the order isn't correct. Bolt shouldn't do 1-2-3-4-5, it should do 1-2-4-3-5. The only issue here is that 2 (the source state update) is not properly ordered.

I won't have time to fix the issue right away, but it will definitely be included in v.1.0.4.

Ah, thats fair.  I think it's still a little counter intuitive to visually see something (the transition) after the state, only to have it do work during it, but it does make sense logically why it would fire before the exit event.

Doesnt really matter to me though, I can work with the update fix alone since I rarely do actual work in the transition :)  Glad the Update event going off late is on your radar now, but don't work too hard , you still have a few days left <3

Fixed in Alpha

Think I got it fixed:



Let me know if you still have issues in v.1.0.4 after it's published!