Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Small bug with Play Mode Options and Awake method on scripts that are marked EecuteInEditMode

Discussion in '2019.3 Beta' started by Kartack, Jan 16, 2020.

Thread Status:
Not open for further replies.
  1. Kartack

    Kartack

    Joined:
    Nov 7, 2012
    Posts:
    11
    Hey, I'm not 100% sure if this is a bug, but I suspect that it is. If you have a script attached to a game object in a loaded scene in the editor, and that script has the ExecuteInEditMode tag, and you have Play Mode Options set such that the scene isn't automatically reloaded as a part of going into play mode, and that script has an Awake method, the Awake method won't be called as a part of setting up the scene. Awake will be called correctly right after code is recompiled (as a part of the forced domain reload at that point, as a part of setting up the object for operation outside of play mode) and as soon as you exit play mode Awake will be called (so as to setup for the script to receive start and update events outside of play mode), but when you then hit play again you will see that OnEnable and Start are called as you would expect on your script but Awake in particular is not called.
    I think this is probably a bug because on scripts that aren't marked as ExecuteInEditMode have their Awake methods called, and the start method on a script that is marked as ExecuteInEditMode will also be called as expected. Similarly, I expect that other discrepancies between PMO and non-PMO like static variables not having their values reset to their default values are expected consequences of turning on PMO and not a "bug". Where as given that Awake is called on other scripts and the other normal object initialized methods are called I suspect this is just an oversight of a very obscure corner case. Hopefully an easy and quick fix.
    Testing was done in PC Unity 2019.3.0f5
    Thanks!
     
    alexeyzakharov likes this.
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    alexeyzakharov likes this.
  3. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    I stopped using ExecuteInEditMode/ExecuteAlways a whole ago. Life is better now.
     
    Kragh likes this.
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,052
    Duplicate. Use topic linked above for discussion of this topic.
     
Thread Status:
Not open for further replies.