Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

TextMesh Pro Inject custom code on TMP_Dropdown show / hide

Discussion in 'UGUI & TextMesh Pro' started by ujz, Jan 8, 2024.

  1. ujz


    Feb 17, 2020
    I wanted to perform some custom code when showing / hiding a dropdown. I wasn't able to find a solution online, so here is my own in case it's useful for anyone in the future:

    Code (CSharp):
    1. using TMPro;
    3. public class CustomDropdown: TMP_Dropdown
    4. {
    5.     protected override GameObject CreateDropdownList(GameObject template)
    6.     {
    7.         //custom logic here when showing the dropdown//
    8.         return base.CreateDropdownList(template);
    10.     }
    11.     protected override void DestroyDropdownList(GameObject dropdownList)
    12.     {
    13.         //custom logic here when hiding the dropdown//
    14.         base.DestroyDropdownList(dropdownList);
    15.     }
    16. }
    Note: In my use case, when the dropdown is shown I lower the CanvasGroup.alpha of other objects to make the dropdown easier to see. And then reverse this when dropdown is hidden.