Subscribe to an Update event in Edit Mode (custom tool)

I need to have a similar Update() callback the same way EditorWindows have by default. I converted a tool from an EditorWindow into an EditorTool.

But the EditorTool only has OnToolGUI and I subscribed to SceneView.duringSceneGui, that is updated everytime you move the mouse over or something is repainted.

But that’s not enough, ssometimes I need to have a method called the same way Update() (at least in general, called constantly, no matter when). But I find no event I can subscribe to for that.

Attributes like [ExecuteAlways] don’t work with these kind of classes, only with MonoBehaviours.

Any idea?

Ok. Found the specific callback: EditorApplication.update
I searched for events but not for callbacks… It’s quite hard to search by hand in the documentation. You have to know the classes.

For people learning about this and future reference, events and callbacks declared for each class in the Scripting Reference can be used to subscribe from our scripts via:

EditorApplication.update += myFunction; // to start it

EditorApplication.update -= myFunction; // to end it

1 Like

Is this what you need?

1 Like

Seems we passed each other on the forums here.

It seems this would suffice. Register during “OnEnable” and unregister during “OnDisable”.

Yes! Thanks
EditorTools have changed in v2020.2+ , so now we have no OnEnable OnDisable (working properly), but instead we have to use OnActivated() and OnWillBeDeactivated() which work perfectly. :slight_smile:

2 Likes