Rendering custom GUI on Scene view

If you’re using assets from the Asset Store then most probably you realized that some scripts introduce custom GUI elements inside the scene view. Custom GUI elements may be very helpful in many cases and they are also easy to implement! Today I’d like to show how to do this.

First, you need to know when custom GUI can be painted. It is done in Editor.OnSceneGUI() method. This means that you need to write a custom editor for any of your components. It should look like this:

This class inherits from Editor class thus let’s call it editor scriptPlease note that all editor scripts should be placed in special Editor directory. If you don’t have any, you can create it anywhere in your project. You can even have multiple Editor directories.


Handles can be the most useful GUI elements that can be painted on a scene. You will be able to use Unity standard handles like position handle, rotation handle, scale handle, and handle types that cannot be found anywhere else.

Let’s create handles fora  script that should draw a Bezier curve from point A to point B. All the drawing will be done in new editor script.


SceneGUIBezierInspector.cs (should be placed in Editor directory)

And here’s how the Scene view will look like after this code is compiled and our script is selected:

handlez bezier curve

Tip: Editor script will not be included in your game. When the unity compiles the project it will intentionally ignore all the scripts inside the Editor directories. So don’t worry about additional or unoptimized code inside your editor scripts.

GUI Elements

You may be familiar with GUI and GUILayout functions. It’s a good method for quick and dirty GUI rendering (yet it is not recommended for production use). These and EditorGUI‘s methods are widely used when it comes to create custom inspector GUI, and it can be used to draw Scene GUI elements as well!

To show this, I will write a dummy script that displays Scene GUI to help to rotate object right and left. It will be dummy because all rotation logic is done in the editor script. It makes sense because this functionality will be useful only in the Unity editor and not in the game. Dummy script comes first:


SceneGUIRotateInspector.cs (should be placed in Editor directory)

Code like this will display GUI elements on our scene when object containing this component is selected. To present this, I’ve created a stretched cube:

scene gui rotate

Unitypackage file

Of course, you can download all the scripts mentioned above (along with the example scenes) as unitypackage file from here. Double-click to import it into your project.

High Definition Render Pipeline: Lit shader in action Part 2
How to achieve realistic results? In a previous post, I was explaining what Lit shader is...
Custom gizmos with OnDrawGizmos
Did you know that by implementing OnDrawGizmos() method in your scripts you can draw a custom...
Profiling Unity Application with Profiler Samples
The Unity Profiler Samples is something that most of Unity users are unaware of. Yet it can...
Call The Knights!
We are here for you.
Please contact us with regards to a Unity project below.

The Knights appreciate your decision!
Expect the first news soon!
hire us!