Skip to main content

TMP Dropdown

TMP_Dropdown is a standard dropdown that presents a list of options when clicked, of which one can be chosen. It should always be used instead of Unity's legacy UI.Dropdown component.

Properties

PropertyTypeDescription
valueintGets or sets the index of the selected element in the dropdown.
IsExpandedboolGets a value indicating whether the dropdown is expanded.
enableboolEnables/disables the attached component

Methods

FunctionInputOutputDescription
SetValueWithoutNotifyintvoidSets the value of the input field without invoking onValueChanged.
RefreshShownValueRefreshes the text and image (if available) of the currently selected option.
ClearOptionsRemoves all options from the dropdown.
ShowShows the dropdown. Plan for dropdown scrolling to ensure dropdown is contained within screen. TMP assumes the Canvas is the screen that the dropdown must be kept inside.
HideHides the dropdown list.

Udon has access to two additional classes related to TMP_Dropdown.

VRCTMPDropdownExtension

This class is part of the VRChat SDK. It allows you to add options to your dropdown.

FunctionInputOutputDescription
AddOptionsTMP_Dropdown,
string[]
Adds the array of strings to the dropdown.
AddOptionsTMP_Dropdown,
sprite[]
Adds the array of sprites to the dropdown.
AddOptionsTMP_Dropdown,
OptionData[]
Adds the array of TMP_Dropdown.OptionData to the dropdown.
Extension method

In UdonSharp, AddOptions is an extension method.

Instead of AddOptions(dropdown, options), you can type dropdown.AddOptions(options). Make sure you have the namespace VRC.SDK3.Components included in the file.

TMP_Dropdown.OptionData

This is built into TextMesh Pro. It allows you to add a combination of strings and sprites to a dropdown.

FunctionsInputOutputDescription
ConstructorstringOptionDataCreates an OptionData object with text as the option.
ConstructorspriteOptionDataCreates an OptionData object with a sprite as the option
Constructorstring, spriteOptionDataCreates an OptionData object with text and a sprite as the option

How to add sprites to a dropdown

Dropdowns can display a different sprite for each option. You need to set up your dropdown correctly:

  1. Add an image to the dropdown.

Add an image to the dropdown hierarchy, moving the label out of the way - part 1 part 2

  1. Add an image to the template.

Add an image to the template hierarchy, moving the label out of the way - part 1 part 2

  1. Add the correct references to Caption Image and Item Image fields in the dropdown.

part 2

  1. Success! The dropdown can now display sprites.