x


Repainting an EditorWindow when it's not the current focus?

I am currently working on a custom EditorWindow for a particular type of GameObject. When I select different objects in the Hierarchy window, the custom window is updated to edit this new object.

This all works fine, except the custom window doesn't redraw until I mouse-over it again. I've tried manually calling Repaint() on the window (didn't work), looked through the documentation and didn't see anything, so now I'm asking here.

How can I repaint a custom EditorWindow when it's not the active focus?

Thanks in advance.

more ▼

asked Dec 18 '10 at 11:46 PM

jbourrie gravatar image

jbourrie
11 2 2 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

...it always seems to work this way, doesn't it? I ask the question after hunting through all the docs, then the minute I post I find the answer :)

For anyone looking at this in the future, EditorWindow.OnGUI() appears to only get called when the window is focused. Moving the Repaint() to EditorWindow.OnSelectionChanged() worked.

more ▼

answered Dec 18 '10 at 11:52 PM

jbourrie gravatar image

jbourrie
11 2 2 3

(comments are locked)
10|3000 characters needed characters left

I've found that adding Repaint() to the Update function of your EditorWindow does the trick. This also has the added effect of repainting the editor window way more often than it does normally which I also found handy in my case.

public void Update()
{
    // This is necessary to make the framerate normal for the editor window.
    Repaint();
}

I suppose if you want your Repaint to be less intrusive you could put it in EditorWindow.OnInspectorUpdate() because it only gets called 10 times per second. That would probably be better for performance.

public void OnInspectorUpdate()
{
    // This will only get called 10 times per second.
    Repaint();
}
more ▼

answered Jan 17 '12 at 09:11 PM

spolglase gravatar image

spolglase
31

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1662
x199
x169
x11
x4

asked: Dec 18 '10 at 11:46 PM

Seen: 2301 times

Last Updated: Jan 17 '12 at 09:11 PM