- Home /
When is Update called in edit mode?
I can't tell exactly when it is called, it is certainly not each frame. It is called sometimes when I change something, but it looks like it is not always called.
When exactly is it called, and is there any way for me to signal an update is necessary from an editor script?
Answer by Bunny83 · May 26, 2011 at 09:31 AM
The editor redraw isn't run in a gameloop like the games you create with Unity. It's completely event based like every window in Windows ;).
OnInspectorGUI or OnGUI in EditorWindows are only called when it needs an update. This is for example when you move the mouse and stop moving for 1 sec the tooltips are displayed. Therefore a repaint is done.
For EditorWindows you can use `EditorWindow.Repaint`. The inspector should be fine.
If you need something that is executed regularly you can use a delegate to hook into the editor update (which runs about 100 times per sec.). This update have nothing to do with visual frames.
If you enable `EditorWindow.wantsMouseMove` for your windows the OnGUI function is called each time you move the mouse, but ONLY to pass a mouseMove event. Still no repaint is done. You can use this code to do a repaint when the mouse is moved.
// C#
void OnGUI()
{
if (Event.current.type == EventType.MouseMove)
{
Repaint();
}
}
If you care about updating the sceneview(s) you can use SetDirty like Tom 17 said or just call Repaint. You can Repaint any EditorWindow as long as you can access it. SetDirty only marks an object to be "dirty" and it needs to be repainted but i guess if ths object isn't visible no repaint is executed (haven't tried).
The SceneView is derived from EditorWindow.SceneView.lastActiveSceneView
gives you the last active sceneview (but check it for non null!!) SceneView.sceneViews is an array that includes all open sceneviews. The sceneview class isn't documented but if you use Visual Studio you have intelliSense ;).
Thank you for this more detailed answer. I think now I know what is going on, and why my code was behaving strangely. I'll verify and then accept the answer ;)
Answer by Tom 17 · May 26, 2011 at 08:52 AM
This works in OnInspectorGUI for custom inspectors
if (GUI.changed)
{
EditorUtility.SetDirty (target);
}
If you meant the Update() function that is available with EditorWindow, that seems to be called frame-indepentently.
If you care to be a bit more specific in your question I will edit my answer to be more precise, too. Though I hope that helped you allready.
Thank you, I think this is what I have been looking for (SetDirty). Unfortunately, I am getting inconsistent behaviour because of another issue, so I can't say for sure. (Once sorted I'll report back).
Answer by tkamruzzaman · May 04, 2016 at 06:55 AM
The functions are not called constantly like they are in play mode. Update is only called when something in the scene changed.
Link: http://docs.unity3d.com/ScriptReference/ExecuteInEditMode.html
Your answer
Follow this Question
Related Questions
Is there a scene setup call or update for editor scripts? 3 Answers
RectTransform.rect.width/height Incorrect On Editor Startup 1 Answer
How to assign multiple EditorApplication.update delegates in JS? 2 Answers
coroutines : trouble editing and accessing the same public variable 4 Answers
Updating assets changes .meta files and breaks dependencies. 1 Answer