- Home /
ExecuteInEditMode is not working.
I have code identical to what you see below. It appears Update does run at least Once, when I first click the scene object, and play with any scene stuff.. but it's definitely not every frame.. In addition neither FixedUpdate or OnGUI are having any effect. I have NOOOO idea what the problem is here, as from everything I read about this, says the code shown below is valid. Placing a () after ExecuteInEditMode changes nothing.
[ExecuteInEditMode] public class MyCustomBehaviour : MonoBehaviour { public void Update() { Debug.Log("."); // Will run in edit mode. }
public void FixedUpdate()
{
Debug.Log("..");
}
public void OnGUI()
{
Debug.Log("...");
}
}
Fixed: For anyone having issues related to this problem, remember that it's not every frame that Update is called.. but only when it is needed to be called.. meaning the objects state much change in some way first.. so I went ahead and created a CustomEditor for my script, and applied EditorUtility.SetDirt(target); inside of OnInspectorGUI();, what that did was tell Unity the objects state has changed, and Unity automatically invokes the scripts Update method(function). Because, OnInspectorGUI is updated each XXX frames, it then updates the script each XXX frames. Sorry for mah retarded moment. Thanks!
"remember that it's not every frame that Update is called.. but only when it is needed to be called."
It is called every frame.. the frames itself just aren't refreshed all that often.
According to the reference: "The functions are not called constantly like they are in play mode. - Update is only called when something in the scene changed."
Also, in Unity 4.2 OnInspectorGUI does not get called at constant time (claimed the OP, "OnInspectorGUI is updated each XXX frames").
Things that do trip the OnInspectorGUI event
Selecting your target object in Scene View
Dragging the Console window around
Clicking randomly in the Inspector Pane
Clicking on objects in the Project
Things that do not cause the event to fire
Just sitting in the editor
Scrolling in the Project list
Flipping between Game and Scene panels
Answer by Eric5h5 · Jun 15, 2010 at 07:12 PM
It's definitely updating every frame. The editor doesn't try to draw frames as fast as possible...that would be a huge waste of CPU time in the editor. It only updates when it needs to (that is, when something changes). OnGUI and Update do work; don't know about FixedUpdate.
How can I get it to update every frame..? It only updates when its neccesary; but the Particle Emitter is able to animate particles each frame, I assume it uses this attribute and runs the code that animates each particle in Update.. so how would I get my system to do that? =|
$$anonymous$$aybe you could let any object oscillate really, really small in your Update()-function? This will probably cause the editor to refresh because something visible has changed.
Additional thought: the particles probably derive from some class (Transform?) which causes a redrawing of the scene on every change.
Particle systems only continuously update as long as they're actively selected. If they're not selected then they don't update.
Any tips on handling user input in an ExecuteOnEdit$$anonymous$$ode component, or is that not advisable? I tried various things, all with curiously delayed results.