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();

		}

	}

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.