Search Unity

Bug Execution of "On Enter State" node inside State Machine happens during Awake step

Discussion in 'Visual Scripting' started by JacobFast, Apr 20, 2022.

  1. JacobFast

    JacobFast

    Joined:
    Apr 29, 2014
    Posts:
    47
    Unity 2021.3.0
    VS 1.7.7

    Happens to custom nodes (not sure if coroutine flag on "On Enter State" has any influence on that), dont know about default nodes.

    VS starts executing all nodes connected to first state machine node "On Enter State" immediately at 0 frame during Awake step.

    Which results in mixed execution order of scene objects Awake methods and custom nodes code. Problem: if the custom node wants data which is being initialized during some scene object MonoBehaviour.Awake call, this data might not be ready. Why this is bad: because execution order is random and might not be noticeable by developer if the random made scene objects awake run before nodes execution, but on different machine the order can change and there will be hard to explain errors.

    What i expect: node execution starts during Start or after all scene objects finished their Awake/Start routine.

    Current solution: connect "Wait for next frame" node to first "On enter state". So the state chain execution starts in 1st frame after all scene objects finished their Awake/Start routine in 0 frame.
     
    Last edited: Apr 20, 2022
    literacy likes this.
  2. literacy

    literacy

    Joined:
    Nov 14, 2021
    Posts:
    56
    Thank you for writing this up! You saved me several hours of work on this Saturday... and I thank you.