Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Error about TMP Dropdown

Discussion in 'Editor & General Support' started by Rachan, Dec 2, 2023.

  1. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    747
    NullReferenceException: Object reference not set to an instance of an object
    PlayerHUD.AddLog (System.String log, System.Boolean replace) (at Assets/Santhai/Scripts/GUI/PlayerHUD.cs:646)
    Santhai.Play2DSound (UnityEngine.AudioClip soundfx, System.Boolean multiple) (at Assets/Santhai/Scripts/GamePlay/GameData.cs:2942)
    Santhai.PlayButtonSound (System.Boolean mul) (at Assets/Santhai/Scripts/GamePlay/GameData.cs:2806)
    GUIOptionMenu.EquipOption (System.Int32 type) (at Assets/Santhai/Scripts/GUI/GUIOptionMenu.cs:71)
    UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <30adf90198bc4c4b83910c6fb1877998>:0)
    UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <30adf90198bc4c4b83910c6fb1877998>:0)
    TMPro.TMP_Dropdown.SetValue (System.Int32 value, System.Boolean sendCallback) (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Dropdown.cs:431)
    TMPro.TMP_Dropdown.set_value (System.Int32 value) (at ./Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Dropdown.cs:406)
    GUIOptionMenu.LoadSetting () (at Assets/Santhai/Scripts/GUI/GUIOptionMenu.cs:383)
    GUIOptionMenu.OnEnable () (at Assets/Santhai/Scripts/GUI/GUIOptionMenu.cs:130)

    I using Unity 2022.3.14f1 and I got this error every time I back to main menu scene
    What happen? and how to fix?

    Thanks!!!
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,354
    It's just a null-ref from your own code. You need to investigate your own code here.
     
    Rachan likes this.
  3. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    747
    Thank you very much!
    But I can't even know where...

    I just go to playing scene and other playing scene,
    and then move back to first scene (mainmenu)
    and then this Error log will show up!
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,354
    Do you not know how to read stack traces? It literally tells you where the error happened. PlayerHUD.cs at line 646.
     
    Rachan likes this.
  5. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    747
    this is when I double crick to that error
    Code (CSharp):
    1. void SetValue(int value, bool sendCallback = true)
    2.         {
    3.             if (Application.isPlaying && (value == m_Value || options.Count == 0))
    4.                 return;
    5.  
    6.             m_Value = Mathf.Clamp(value, m_Placeholder ? -1 : 0, options.Count - 1);
    7.             RefreshShownValue();
    8.  
    9.             if (sendCallback)
    10.             {
    11.                 // Notify all listeners
    12.                 UISystemProfilerApi.AddMarker("Dropdown.value", this);
    13.                 m_OnValueChanged.Invoke(m_Value);
    14.             }
    15.         }
    and this is line 646

    Code (CSharp):
    1. DropdownItem item = itemToggle.gameObject.AddComponent<DropdownItem>();
    and I can't even changing anything in this script, if I modified something and save, then it restore to before.
     
  6. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,354
    Likely the error opens the Unity UI package code because it happened in a callback. Still doesn't change the fact that the error is in your own code.
    itemToggle
    is null. Figure out why it ends up null and fix it.
     
    Rachan likes this.