- Home /
How to manually update GameView?
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.
Answer by Majnun · Jan 13, 2014 at 04:13 AM
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).
UnityEditorInternal.InternalEditorUtility.RepaintAllViews()
Answer by Zebibto · Aug 15, 2013 at 02:03 PM
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:
gameview.Repaint();
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.
Also see http://answers.unity3d.com/questions/9574/manually-updateredraw-scene-view.html
Related, but not sure if that redraws the game view.
Just in case anybody is finding this helpful. The variable name in the second line should be replaced by this
System.Type type = assembly.GetType( "UnityEditor.GameView" );
Answer by pctroll · Dec 29, 2013 at 06:37 PM
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();
This works, however, it causes the inputfields (like EditorGUILayout.FloatField()) to become uneditable, so they become useless. Any way around that?
Your answer
Follow this Question
Related Questions
Add and Select Game View Resolution Programatically 5 Answers
ReadPixels to capture GameView in EditMode and "Pixels out of bounds" 3 Answers
Game object is visible in scene tab,but not in the game tab. 17 Answers
Stepping through WaitForEndOfFrame when GameView isn't visible 1 Answer
GameView reduced to a reasonable size for this system 0 Answers