Version: 2018.3 (switch to 2019.1)
LanguageEnglish
  • C#

DefaultControls

class in UnityEngine.UI

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Utility class for creating default implementations of builtin UI controls.

The recommended workflow for using UI controls with the UI system is to create a Prefab for each type of control and instantiate those when needed. This way changes can be made to the Prefabs which immediately have effect on all used instances.

However, in certain cases there can be reasons to create UI controls entirely from code. The DefaultControls class provide methods to create each of the builtin UI controls. The resulting objects are the same as are obtained from using the corresponding UI menu entries in the GameObject menu in the Editor.

An example use of this is creating menu items for custom new UI controls that mimics the ones that are builtin in Unity. Some such UI controls may contain other UI controls. For example, a scroll view contains scrollbars. By using the DefaultControls methods to create those parts, it is ensured that they are identical in look and setup to the ones provided in the menu items builtin with Unity.

Note that the details of the setup of the UI controls created by the methods in this class may change with later revisions of the UI system. As such, they are not guaranteed to be 100% backwards compatible. It is recommended not to rely on the specific hierarchies of the GameObjects created by these methods, and limit your code to only interface with the root GameObject created by each method.

Static Methods

CreateButtonCreate a button.
CreateDropdownCreate a dropdown.
CreateImageCreate an image.
CreateInputFieldCreate an input field.
CreatePanelCreate a panel.
CreateRawImageCreate a raw image.
CreateScrollbarCreate a scrollbar.
CreateScrollViewCreate a scroll view.
CreateSliderCreate a slider.
CreateTextCreate a text object.
CreateToggleCreate a toggle.

Did you find this page useful? Please give it a rating: