Error about TMP Dropdown

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.InvokableCall1[T1].Invoke (T1 args0) (at <30adf90198bc4c4b83910c6fb1877998>:0) UnityEngine.Events.UnityEvent1[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!!!

It’s just a null-ref from your own code. You need to investigate your own code here.

1 Like

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!

Do you not know how to read stack traces? It literally tells you where the error happened. PlayerHUD.cs at line 646.

1 Like

this is when I double crick to that error

void SetValue(int value, bool sendCallback = true)
        {
            if (Application.isPlaying && (value == m_Value || options.Count == 0))
                return;

            m_Value = Mathf.Clamp(value, m_Placeholder ? -1 : 0, options.Count - 1);
            RefreshShownValue();

            if (sendCallback)
            {
                // Notify all listeners
                UISystemProfilerApi.AddMarker("Dropdown.value", this);
                m_OnValueChanged.Invoke(m_Value);
            }
        }

and this is line 646

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.

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.

1 Like