Entering PlayMode execution order
Hi,
I built this small diagram showing what I've observed from Unity script execution order when going from EditMode to PlayMode:
EditorScripts is a script ihneriting from Editor and ExecuteAlways is a script that runs in edit mode and play mode. Global are static calls made with special Unity Attributes.
What I know is that Unity needs to Serialize the data before doing in play mode, so that it can revert back any changes made while in play mode. From that, steps 1,2,3 make sense, but I'm not sure to understand why steps 4,5,6,7 exist. For me, this looks like if there was a serialized state between EditMode and PlayMode. For ExecuteAlways, if our script runtime instances are created after step 8, why on earth are they Enabled/Disabled/Destroyed (5-7) ?
The problem with this is that when I do a lot of stuff in OnEnable, like subscribing to events from a global service, I will do this twice each time I go in play mode, because we will do this at step 5 and step 10.
Thank you!
Answer by Bunny83 · Jul 24, 2019 at 01:15 AM
This seems to be more or less a duplicate of this one or at least is related to the same internal mechanics.
Answer by unity_AOt7DUeozxzLxA · Aug 06, 2019 at 12:09 PM
This is not a direct answer, but for people coming on this post, with the new fast enter play mode in 2019.3, the execution pipeline is greatly simplified/more intuitive. This is what I get with some observations in 2019.3.0a11:
Your answer
![](https://koobas.hobune.stream/wayback/20220612205358im_/https://answers.unity.com/themes/thub/images/avi.jpg)