Search Issue Tracker
By Design
Votes
10
Found in
4.3.0b6
Issue ID
571898
Regression
No
Awake & Start not called before Update when assembly is reloaded for ExecuteInEditMode scripts
To reproduce:
1. Open the attached project
2. Observe that "Awake", "Start", "Update" is displayed in the console (because of the ExecuteInEditMode script)
3. Reimport the script to trigger recompile
4. Move the camera around
5. Notice that "Update" is called without any calls to "Awake" and "Start"
Note:
Awake and Start are not called on the object because they were already called on this object upon its first creation. On load, the object state is serialized (public and private variables) and then deserialized. When deserialization happens, as long as the object already existed, Awake nor Start are not invoked.
This is by design, and it's tightly coupled in the MonoBehaviour lifecycle. Changing this behavior will possibly impact on all the projects that don't expect Awake/Start to be invoked.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- “Readme” Asset is unreadable in the Inspector window when switching Editor Theme to Light
- “NullReferenceException” error thrown when switching Editor Theme to Light if “Unity Version Control” tab is enabled
- A Warning is displayed in the Inspector when a Mesh with any Material is added as a Terrain Detail
- [Android][Vulkan] Memory leak when playing and stopping a video using the Video Player on some devices
- Caret moves by a character when typing "." and any number into 'Grid and Snap' toolbar's input field
Hullabu
Jun 05, 2019 12:49
This is 100% bug and this is a shame that it is not fixed yet
wgamestom
Dec 03, 2018 01:20
While I agree that this bug should be fixed, you can get around it pretty easily by relying on OnEnable and OnDisable for your needs.
I've started to use Awake for Serialized Properties, and OnEnable and OnDisable for NonSerialized Properties.
OnEnable and OnDisable are especially good for adding and removing listeners to other objects in Editor Mode.
ercion
Nov 04, 2017 12:46
Why wontfix?
farshidhss
Oct 22, 2017 15:05
+1 to know why not fix this!
keni4
Aug 15, 2017 13:51
It is a bug. Why it is Won't fix?
vjyourself
Jul 30, 2017 09:30
yes it's definitely an annoying bug, and goes against the documentation. Really pure attitude from the Unity Staff to flag it 'Won't Fix" without any explanation !
roberteker
May 15, 2017 10:51
I also encountered this bug just now. Why is this a won't fix?
cleod9
Mar 24, 2017 18:25
+1 to knowing why this ticket has been abandoned. Even a "this is not a priority for us" would be an acceptable answer.
But for anyone else who lands on this, I was able to work around it by manually calling Start() again if things look amiss. e.g:
void Update() {
if (Application.isEditor && !Application.isPlaying && anyClassVarThatShouldntBeNull == null) {
Start(); // Or whatever other method re-initializes your vars
}
}
Chazmundo
Mar 15, 2017 10:50
+1 to knowing why this isn't a Won't Fix.
scabnog
Aug 20, 2016 14:44
I would also like to know why this has been marked as Won't Fix?
ExecuteInEdit mode allows objects to be initialized and updated via Awake/Start/Update, but saving a script breaks all the connections. This feature appears fundamentally broken if it only works until you make a change to a script.
As for OnValidate - while this does get called after reloading scripts, it does not respect ScriptExecutionOrder, so it is not equivalent or suitable as a drop-in replacement for Awake/Start.