Skip to content

GUI vs GUILayout vs EditorGUI vs EditorGUILayout and When to Use Them – Unity

The Unity GUI API classes are fairly similar, so it’s worth clarifying their use cases.

GUI vs EditorGUI

The difference between GUI and EditorGUI is primarily just their use case. GUI is used to display GUI items in game. GUI was the original way of creating Unity UI before their new canvas APIs. EditorGUI is used to create custom editors for your scripts and other editor customization.

One exception to that rule is that certain GUI classes are used for both. For instance, GUISkin and GUIStyle are used by both and their current values are accessed using GUI.skin regardless if used in game or in editor.

GUI vs GUILayout (and EditorGUI vs EditorGUILayout)

GUILayout and EditorGUILayout are basically wrappers around GUI and EditorGUI that set the position rect for your fields automatically. The Unity documentation refers to this as automatic layout. In general, it’s more convenient and minimizes boilerplate code.

Use cases for not using the automatic layout versions are when there is not automatic layout version available (such as with ProgressBar or DrawPreviewTexture) and when you are given a rect and must manually layout your rect and pass it to your fields (such as in the drawElementCallback of a ReorderableList).

Summary

Generally, the choice of which class to use just comes down to your use case.

Tl;DR: Use the Layout versions to automatically layout and GUI for in game and Editor for in editor!

Published inCode ExamplesDesign TipsDevelopment Tips

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *