Search Unity

m_AlphaTweenRunner not initialized in TMP_Dropdown

Discussion in 'UGUI & TextMesh Pro' started by wx3labs, Mar 9, 2021.

  1. wx3labs

    wx3labs

    Joined:
    Apr 5, 2014
    Posts:
    77
    I've periodically run into this error with TMP_Dropdown when clicking on a dropdown for the first time in playmode:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. TMPro.TMP_Dropdown.AlphaFadeList (System.Single duration, System.Single start, System.Single end) (at Library/PackageCache/com.unity.textmeshpro@3.0.4/Scripts/Runtime/TMP_Dropdown.cs:1072)
    3. TMPro.TMP_Dropdown.Show () (at Library/PackageCache/com.unity.textmeshpro@3.0.4/Scripts/Runtime/TMP_Dropdown.cs:890)
    4. TMPro.TMP_Dropdown.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.textmeshpro@3.0.4/Scripts/Runtime/TMP_Dropdown.cs:707)
    5. UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2020.2.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
    6. UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2020.2.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:262)
    7. UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2020.2.6f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:385)
    8.  
    The offending line in TMP_Dropdown is:

    m_AlphaTweenRunner.StartTween(tween);

    It would appear that TMP_Dropdown isn't checking that m_AlphaTweenRunner is initialized before trying to start the tween.

    m_AlphaTweenRunner appears to be initialized in "Awake" so that shouldn't be possible if the dropdown is active, so I am at a loss as to what is happening.

    I'm in 2020.2.6f1 with TextMeshPro 3.0.4, but the problem existed in 2019.2 and TextMeshPro 3.0.3.
     
    Babiole likes this.
  2. Babiole

    Babiole

    Joined:
    May 7, 2016
    Posts:
    17
    I had the same issue with Unity 2020.3.1f1 and TextMeshPro 3.0.4, I managed to fix it by changing this line from the package :

    Line 349 of TMP_Dropdown.cs
    Replace this line
    Code (CSharp):
    1. private TweenRunner<FloatTween> m_AlphaTweenRunner;
    by
    Code (CSharp):
    1. private TweenRunner<FloatTween> m_AlphaTweenRunner = new TweenRunner<FloatTween>();
    For some reason the Awake() function of TMP_Drowndown isn't called so TweeRunner isn't initialized, and TMPro.TMP_Dropdown.OnPointerClick called TweeRunner, that haven't been initialize inside the Awake()

    PS: You had to modify the TMP_Drowndown.cs from [User]\AppData\Local\Unity\cache\packages\packages.unity.com\com.unity.textmeshpro@3.0.4\Scripts\Runtime not the one in your project cache otherwise Unity will overwrite your change
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The reason Awake is no longer called is due to the recently added Enter Play Mode Settings.

    The following change should resolve this issue when Domain Reload is disabled in the Enter Play Mode Settings.

    upload_2021-4-5_14-50-2.png
     
    Babiole likes this.
  4. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Hi Stephan, will this change be included in the next version of TMPro?
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Assuming it appears to be working as expected on your end. Yes ;)

    Will also be adding support for Multi Select to the TMP Dropdown.
     
    Korindian likes this.
  6. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Just did some testing, and it seems to work with that fix without problems with altered Enter Play Mode Settings.
     
  7. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    Yes, but this fixed on a problem in a very narrow case (domain reloading which doesn't really scale well on projects larger than a demo, not without significant work) and instead induced an error for the majority of us that don't use the play mode options (using the 3.0.6 now), specifically I cannot have a dropdown starting with its game object de-activated and show it on-demand immediately because it now needs to wait for its Start().

    As a workaround, I'm calling Start() manually after activating the game object, but I don't feel good about it. Hope you'll fix this in next versions