Search Issue Tracker
Won't Fix
Votes
0
Found in
2019.1.0a11
2019.1.0a14
Issue ID
1117136
Regression
Yes
Functions called by UI Toggles before Start() resulting in NullReferenceException spam
Repro step:
- download and open this project
- press play
- notice the Null Reference exceptions:
NullReferenceException: Object reference not set to an instance of an object
Rolloff.ChangeRolloff () (at Assets/Audio Manager/Rolloff.cs:43)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent`1[System.Boolean].Invoke (Boolean arg0) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_1.cs:63)
UnityEngine.UI.Toggle.Set (Boolean value, Boolean sendCallback) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Toggle.cs:274)
UnityEngine.UI.Toggle.set_isOn (Boolean value) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Toggle.cs:237)
UnityEngine.UI.ToggleGroup.RegisterToggle (UnityEngine.UI.Toggle toggle) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/ToggleGroup.cs:87)
UnityEngine.UI.Toggle.SetToggleGroup (UnityEngine.UI.ToggleGroup newGroup, Boolean setMemberValue) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Toggle.cs:185)
UnityEngine.UI.Toggle.OnEnable () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Toggle.cs:144)
- This is because the ChangeRolloff function- assigned to an UI Toggle, is called before Start() of the main Rolloff class and, therefore the objects inside don't get initialised
- also, on exiting play mode, the ChangeRolloff toggle gets activated again causing more errors in the console:
Assertion failed on expression: 'go.IsActive()'
UnityEngine.GameObject:Find(String)
Rolloff:ChangeRolloff() (at Assets/Audio Manager/Rolloff.cs:47)
UnityEngine.UI.Toggle:OnDisable()
Cannot reproduce with: 2019.1.0a10 and 2018.3.1f1
Reproducible with: 2019.1.0a11 and 2019.2.0a1
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Search field in UI Builder's Library has no character limit
- Changing the value in UI Builder by dragging increases it by a few thousand points when reaching the borders of the screen
- ARM64 architecture DLL incorrectly copied instead of x64 when building for Windows x64
- Crash on TypeTreeIterator::GetNode when opening a specific folder
- Crash on WriteSerializedAssetsV2 when (re)entering the Play Mode in a specific project when IEnumerator Start() is used
Resolution Note (2019.2.X):
The UI needs to send the notification when it is ensuring only 1 toggle is on when you enter play mode. The issue is this code does run before Start. User project needs to change to prevent the null reference from happening. Ensure the object you are accessing is not null is good practice.