Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
14
Question by Stelimar · Dec 30, 2009 at 10:48 PM · editor-scriptingsceneviewgizmo

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?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image grimmy · Jan 10, 2014 at 05:40 PM 0
Share

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..

avatar image yoyo grimmy · Jan 11, 2014 at 06:27 AM 0
Share

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.

avatar image LukeNukem44 grimmy · Mar 06, 2018 at 09:34 AM 0
Share

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.

7 Replies

· Add your reply
  • Sort: 
avatar image
46
Best Answer

Answer by mbysky · Mar 07, 2012 at 03:57 AM

SceneView.RepaintAll(); You can try this, it works for me.

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image donhelms · Aug 16, 2012 at 08:38 PM 0
Share

Thanks for the snippet! This worked for me as well.

avatar image PatHightree · May 23, 2013 at 11:58 AM 0
Share

Does what it says on the tin, worked as advertised.

avatar image mandos78 · Jun 10, 2013 at 06:39 PM 0
Share

This is the solution that works, HandleUtility.Repaint() doesn't do the trick, as commented before

avatar image Lukas_GMC · Oct 24, 2013 at 07:09 PM 0
Share

This should be the accepted answer!

avatar image marcin-matczak · Jun 08, 2020 at 01:16 PM 2
Share

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.

Show more comments
avatar image
23

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"

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hardwire · May 05, 2011 at 07:51 PM 1
Share

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 :)

avatar image yoyo · Sep 07, 2011 at 11:19 PM 0
Share

+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?

avatar image BMYU · Jul 14, 2014 at 05:48 AM 0
Share

This works great. Nice!

avatar image fer-geraci · Mar 07, 2016 at 09:34 PM 0
Share

This is the right answer.

avatar image lborreroluz · Dec 18, 2017 at 10:01 PM 0
Share

I force it without the condition. EditorUtility.SetDirty (target); Works perfect!

avatar image
8

Answer by Jaap Kreijkamp · Jan 01, 2010 at 02:50 AM

I believe HandleUtility.Repaint does what you want.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ClandestineMan · Oct 20, 2010 at 05:16 PM 0
Share

This only works in the editor. You can not build the project with this code in it. Any other ideas?

avatar image Jaap Kreijkamp · Nov 10, 2010 at 03:49 AM 2
Share

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.

avatar image yoyo · Sep 07, 2011 at 11:19 PM 0
Share

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).

avatar image
3

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image demented_hedgehog · Sep 17, 2015 at 04:26 AM 0
Share

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).

avatar image Hurri04 · Mar 03, 2019 at 09:59 AM 0
Share

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);
     }
avatar image
2

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image daiyukun2013 · Mar 21 at 04:39 PM 0
Share

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.

  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to hide Gizmos by script 4 Answers

Drawing to scene view from EditorWindow? 2 Answers

Custom scene view in editor window 2 Answers

Using Handles.DrawAAPolyLine 1 Answer

OnSceneGUI event Use() ates too much :) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges