Z
Z
Zimaell2021-02-13 16:43:01
Unity
Zimaell, 2021-02-13 16:43:01

From what can be an error in the selective menu?

In general, in my code there is a selective menu for choosing languages, after choosing a language in (On Value Changet (Int32)) I use the following method

public  int Language = 0;
public GameObject DropdownLanguage;
public void SetLanguage(){
        Language = DropdownLanguage.GetComponent<Dropdown>().value;
        PlayerPrefs.SetInt("Language", Language);
        PlayerPrefs.Save();
        }

It worked properly without any bugs, and then during the next test I got this error 3 times
spoiler
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.Dropdown.AlphaFadeList
(System.Single duration, System.Single start, System.Single end)
(at C:/Program Files/Unity/Hub/Editor/2020.2.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Dropdown.cs:1049)
UnityEngine.UI.Dropdown.Show ()
(at C:/Program Files/Unity/Hub/Editor/2020.2.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Dropdown.cs:866)
UnityEngine.UI.Dropdown.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData)
(at C:/Program Files/Unity/Hub/Editor/2020.2.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Dropdown.cs:685)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData)
(at C:/Program Files/Unity/Hub/Editor/2020.2.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
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.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:262)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2020.2.1f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:385)

while the selective menu itself hung and did not disappear.
I stopped the test and started it again, I didn’t even change anything, no more errors popped up, and now I’ve been checking without changes and no errors yet ...

So I didn’t understand why this error got out, whether it will come out again when any ...
What tell me in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-02-13
@Zimaell

Something didn't initialize somewhere.
If the tests are automatic - it is quite possible that you need to insert an expectation of SOMETHING (but not in time!) - such as the same Start or Awake
In general, you need to look at the logic and look at the crash site

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question