Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
1
Question by RyuBlue · Jan 20, 2014 at 04:40 PM · editorwindowsceneviewhandlesonscenegui

Is it safe to call SceneView.RepaintAll() frequently?

Hello! I'm creating a simple level editor to get my hands dirty with some Editor/Window scripts. I was having a problem where a Rect drawn on the scene view that follows the mouse would only update once every second or two giving the impression of lag.

What fixed it was simply adding SceneView.RepaintAll(); within OnSceneGUI

I'm just wondering whether there was a reason RepaintAll() wasn't being called frequently? Am I going to run in to issues laters on if RepaintAll is called as often as I am?

Thanks!

This is my OnSceneGUI code:

 void OnSceneGUI(SceneView sceneView)
     {
         float size_x = tiles.x;
         float size_y = tiles.y;
 
         if (showGrid)
         {
             // Draw all X grid lines
             for ( int i = 0; i <= size_x; i++ )
             {
                 // draw a line equal to x and the full height
                 Handles.DrawLine( new Vector3(i,0,0), new Vector3(i,size_y,0) );
             }
             
             // Draw all y grid lines
             for ( int i = 0; i <= size_y; i++ )
             {
                 // draw a line equal to x and the full height
                 Handles.DrawLine( new Vector3(0,i,0), new Vector3(size_x,i,0) );
             }
         }
 
         // check if mouse is over any tiles
         Vector3 mousePosition = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).origin;
 
         if ( (mousePosition.x > 0 && mousePosition.x < size_x) && (mousePosition.y > 0 && mousePosition.y < size_y) )
         {
             // mouse is within a tile
             int hoverTile_x = (int)Mathf.Floor( mousePosition.x );
             int hoverTile_y = (int)Mathf.Floor( mousePosition.y );
 
             Vector3[] hover_verts = new Vector3[4];
             hover_verts[0] = new Vector3(hoverTile_x,hoverTile_y + 1,0);
             hover_verts[1] = new Vector3(hoverTile_x + 1,hoverTile_y + 1,0);
             hover_verts[2] = new Vector3(hoverTile_x + 1,hoverTile_y,0);
             hover_verts[3] = new Vector3(hoverTile_x,hoverTile_y,0);
             Handles.DrawSolidRectangleWithOutline( hover_verts, new Color(0f,1f,1f,0.5f), Color.white );
 
             SceneView.RepaintAll();
 
         }
 
     }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dsnettleton · Mar 30, 2015 at 12:12 AM

As long as you're only doing it when you need to update the rectangle (such as when dragging the mouse, etc), I don't see a problem with it at all. I would recommend checking to see whether your hoverTile coordinates have changed before bothering to repaint the scene view in the code you posted. Otherwise, it's fine.

Comment
Add comment · 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

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

19 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 avatar image avatar image avatar image

Related Questions

Why does the SceneView camera return jittery values? 0 Answers

Using Handles class 2 Answers

Keep multiple custom handles visible in the Scene view 0 Answers

Change SceneViewState via code (Fog, Skybox, Animated Materials, Image effects, etc)? 0 Answers

Camera properties jitter in OnSceneGUI 0 Answers


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