- Home /
How To Force an Inspector to Repaint
In an inspector I'm invoking a Coroutine. When the Coroutine finishes I want the Editor to Repaint(). However, calling Repaint() from the Coroutine's callback doesn't Repaint(). Is there a simple solution to this that I'm missing?
Thanks,
How are you invoking your coroutine? I'm assu$$anonymous$$g you have verified that it actually finishes.
@Adam-$$anonymous$$echtley, the only way I know how to invoke a $$anonymous$$onoBehaviour::StartCoroutine()
is with an instance of a component bound to a GameObject
- in this instance, the Editor.target
of the custom inspector I'm using.
However, @Glurth's insight pointed me toward the actual issue (how the editor interprets yield functionality).
Answer by LW · Sep 16, 2016 at 03:55 PM
I've written a short workaround for how the Unity editor handles yield instructions within the editor space (shown below):
protected System.Collections.IEnumerator CoQuery()
{
bool bStillWorkingOnSomething = true;
#if UNITY_EDITOR
if (!Application.isPlaying)
{
while (bStillWorkingOnSomething)
{
/* When done doing what your doing... */
bStillWorkingOnSomething = false;
}
}
else
{
#endif // UNITY_EDITOR
yield return new WaitForSeconds(1); // Or something similar...
#if UNITY_EDITOR
}
#endif // UNITY_EDITOR
}
Hopefully, this can help someone in the future.
Answer by Glurth · Sep 16, 2016 at 01:04 AM
the only way I've found to do this, consistantly, is to override the Editor's RequiresContantRepaint function eg
override public bool RequiresConstantRepaint() { return (repaintCondition1 || repaintCondition2); }
Ty @Glurth, you helped me realize the problem wasn't where I was ignorantly looking.
The issue wasn't with repainting rather it has to do with how Unity utilizes yield instructions.
Thank you so much for this. This is so much simpler than the Best Answer that the OP posted! I've been trying to get this Repaint to work for 30 $$anonymous$$utes.
A little old but... yeah, if you read what I wrote the problem wasn't in repainting but in how the yield instruction was handled in editor.
If you just need to repaint you override RequiresConstantRepaint.
If you need to query until you get a response you would use what I wrote or something similar.
Absolutely! I didn't mean to denigrate your answer, but it was a bit over my head! The one-liner suits my needs for now. Once I become more advanced with Unity and create more sophisticated custom editor windows, I'll revisit this to get a better understanding.
Answer by LW · Sep 16, 2016 at 02:07 PM
Wow, I love how I'm not good enough to comment on a reply in a thread I've started....
@Glurth, I've tried to override UnityEditor.Engine::RequiresConstantRepaint()
but that doesn't get the update to occur. Which makes me think this isn't the actual problem.... I need to do more digging.
I will post what I find.