I have an inspector script that modifies a Bounds value of a MonoBehaviour. That MonoBehaviour also has a OnDrawGizmosSelected that draws a rectangle based on that Bounds value. For convenience I would like to modify the value while looking at the GameView and seeing the results of the update immediately. However, while the value is being updated correctly the rectangle in GameView is not updated until I focus the gameview by clicking on it. Is there a way to force the GameView to update (or force OnDrawGizmosSelected)? I know how to do it using the scene view and that works fine, but I’d like to see it in the GameView.
Found this solution after scouring the internet. Doesn’t seem well documented at all, so not sure how reliable it will be in the future. Works for me with 4.3.2 with case I was having trouble with (GameView not updating after I changed an object with a custom Editor Window).
To get a reference to the GameView :
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly; Type type = assembly.GetType(name); EditorWindow gameview = EditorWindow.GetWindow(type);
Then simply call:
This works for me in Unity 4.2.0, but I’m not sure why you can’t just use UnityEitor.GameView directly. Other examples I found seem to be able to do this.
So, wrapping-up all the answers and comments, this is the definite answer to the question.
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly; System.Type type = assembly.GetType( "UnityEditor.GameView" ); EditorWindow gameview = EditorWindow.GetWindow(type); gameview.Repaint();