- Home /
Manually Update/Redraw Scene View?
I have a GameObject whose gizmo is drawn differently depending on certain properties of the GameObject which are modified through a custom editor I've created for it. As it is now, if I modify one of the properties, the gizmo isn't redrawn until I click in the scene view. Is there any way to manually update the either the scene view or just the gizmo when one of the properties is modified?
SceneView.RepaintAll(); seems to be the answer, but where on earth do I put this code?
In A script that has ExecuteInEdit$$anonymous$$ode inside? or in another script kept in an Editor folder?...or in a custom inspector? I've heard so many different things I don't know where this snippet is supposed to go..
This isn't really an answer is it? Follow-up questions should be added as comments on the answer you want more information about. If your case is like the original question then call this code when your custom editor changes the object whose gizmo needs to be redrawn.
Never$$anonymous$$d grumpy yoyo... That's a great question, grimmy, about where the code should go. It is very relevant. No good giving us a puzzle piece without telling us where it goes! If you're not writing an editor script, put it in “void OnDrawGizmos()” or “void OnDrawGizmosSelected()” in a $$anonymous$$onoBehaviour script attached to a GameObject in-scene. This is something you would do when you want certain editor behaviors to occur, whether in GameObject components including custom scripts or effects in the actual scene view like gizmos.
Answer by mbysky · Mar 07, 2012 at 03:57 AM
SceneView.RepaintAll(); You can try this, it works for me.
This is the solution that works, HandleUtility.Repaint() doesn't do the trick, as commented before
This doesnt work, nor any of those:
Canvas.ForceUpdateCanvases();
EditorWindow.GetWindow( Type.GetType( "UnityEditor.GameView,UnityEditor" ) ).Repaint();
SceneView.RepaintAll();
EditorWindow.GetWindow<SceneView>().Repaint();
HandleUtility.Repaint();
I need to grab a side of a window and resize it a little bit. Only then the window actually redraws. But I would like to do this from code.
Answer by mihapro · Jan 19, 2011 at 07:15 AM
You should use this code:
if (GUI.changed) EditorUtility.SetDirty (target);
For more details see the documentation "LookAtPointEditor.js"
This works although it marks the scene as unsaved. In my case I need to redraw the scene when the user changes the current tool in the inspector, which obviously doesn't make any change to the component itself. But the scene must be redrawn to display a different set of handles. But I guess I can live with it :)
+1, this worked for me. Agreed on not liking the dirtying of the scene, but I can also live with it. Has anyone filed a bug report about HandleUtility.Repaint not doing what it seems like it ought to?
I force it without the condition. EditorUtility.SetDirty (target); Works perfect!
Answer by Jaap Kreijkamp · Jan 01, 2010 at 02:50 AM
I believe HandleUtility.Repaint does what you want.
This only works in the editor. You can not build the project with this code in it. Any other ideas?
Should be in Editor folder of your scripts as it is editor functionality, you don't have a scene view in final build, so what use would it be to have it compiled in project.
It sounds like it should do what the OP wants, but it doesn't seem to work. I have the same issue. HandleUtility.Repaint doesn't refresh my scene view (I'm on Unity 3.3 on a Windows PC).
Answer by glaucomorais · Apr 13, 2014 at 03:15 AM
You can use EditorUtility.SetDirty(target) to update handles. But, to avoid to mark the scene aways as unsaved, you must do a trick like this:
var int lastValue = someValue;
someValue = EditorGUILayout.IntField("Value", someValue);
if (someValue != lastValue) {
EditorUtility.SetDirty(target);
}
Recently I implemented a Spawn system that have a custom inspector. Here is the inspector in action: http://gyazo.com/5c2f5f12a1d60e950aa62f21629f9866
This worked for me.. Other solutions did not (UI Text was failing to redraw in its new position straight away when it's parent ganeObject moved in the Editor).
This worked for me, although I changed the condition a bit:
if(Event.current.rawType == EventType.$$anonymous$$ouse$$anonymous$$ove ||
Event.current.rawType == EventType.$$anonymous$$ouseEnterWindow ||
Event.current.rawType == EventType.$$anonymous$$ouseLeaveWindow)
{
EditorUtility.SetDirty(target);
}
Answer by CrandellWS · Dec 12, 2017 at 12:02 PM
First you need to set the Gameobject as dirty, then repaint.
GameObject targetGameObject;
EditorUtility.SetDirty(targetGameObject);
SceneView.RepaintAll ();
This may also help other future readers:
https://docs.unity3d.com/ScriptReference/EditorWindow.OnHierarchyChange.html
I confirm this answer works, only call RepaintAll() cannot auto-refresh the scene (at lease when I edit the prefab), add SetDirty makes it auto-refresh the scene.
Your answer
Follow this Question
Related Questions
How to hide Gizmos by script 4 Answers
Constantly Update Scene View 1 Answer
How to make a script generated mesh pickable(selectable) in the scene view (Problem with normals)? 0 Answers
How to create a floating window in the scene view? (As with Navmesh and Lightmapping) 0 Answers
Handles Mouse Event Drag not working 1 Answer