Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Weird problem with TMP_Dropdown

Discussion in 'UGUI & TextMesh Pro' started by wx3labs, Dec 1, 2020.

  1. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    75
    (This is a repost from the scripting forum that someone suggested I try here):

    I've run into a problem that's got me stumped. I have a standard TextMeshPro Dropdown that's throwing an exception when expanded because its m_AlphaTweenRunner property isn't initialized. I added some debug statements to the component's Awake and Start methods to figure out why:

    Code (CSharp):
    1. protected override void Awake()
    2.         {
    3.             Debug.Log("Okay! I'm awake: " + this.GetType().Name);
    4. #if UNITY_EDITOR
    5.             if (!Application.isPlaying)
    6.                 return;
    7. #endif
    8.  
    9.             m_AlphaTweenRunner = new TweenRunner<FloatTween>();
    10.             m_AlphaTweenRunner.Init(this);
    11.  
    12.             if (m_CaptionImage)
    13.                 m_CaptionImage.enabled = (m_CaptionImage.sprite != null);
    14.  
    15.             if (m_Template)
    16.                 m_Template.gameObject.SetActive(false);
    17.         }
    18.  
    19.         protected override void Start()
    20.         {
    21.             Debug.Log("Now I've started: " + this.GetType().Name);
    22.             base.Start();
    23.  
    24.             RefreshShownValue();
    25.         }
    When run, the first thing I see is "Now I've started: TMP_Dropdown" in the console, nothing from the Awake method.

    My understanding is that Awake should always execute before Start. But somehow here it seems not to. How is that possible? Apart from those debug lines, this is an unmodified TextMeshPro 2.1.3 package.

    (The Awake and Start debug lines both show up when I exit play mode.)

    This is in 2019.4.10f1 and 2019.4.15f1.
     
    nick-morhun likes this.
  2. nick-morhun

    nick-morhun

    Joined:
    May 12, 2015
    Posts:
    47
    In TextMesh Pro 3.0.6 you still cannot show a dropdown before Start().
     
  3. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    755
    I'm calling Start() manually after having activated the game object and it seems to work well.

    I wouldn't bet on it long-term, though