- Home /
void OnEnable() is called Unpredictably in Editor Mode
I implement OnEnable() and it is call always called in Play mode as expected. But in Editor Mode some components call OnEnable() and other don't
I need OnEnable() or other method to be called in Editor Mode to setup component to be able to prototype.
If I extend class from UnityEngine.UI.Image then OnEnable() is called in Editor Mode. If I extend class from MonoBehavior then it does not call OnEnable() in Editor Mode but still calls it in Play Mode.
Is there any clarification why it is called or not called.
Answer by _dns_ · Mar 10, 2017 at 04:12 PM
Hi, would it be because of the ExecuteInEditMode attribute ? (https://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html). If you derive from a (monobehavior based) class that has this attribute, it will propagate to derived classes. You should also use the Application.IsPlaying flag to know if you are in editor mode or not during OnEnable/Disable, Update etc...
Your answer
![](https://koobas.hobune.stream/wayback/20220612112842im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UI - clamp the movement of a panel 0 Answers
Difficulties with world space canvas interaction 1 Answer
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
Getting the overlapping pixels between a UI mask and a UI image 0 Answers
UI button are sliced after exporting 0 Answers