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
- Physics SyncColliders 3x-7x performance regression from 2022LTS to U6
- ListView's '+' button causes a recursively dispatching event when the visual element area is filled up
- Soft keyboard closes immediately after multiple touches are made if Pointer Behavior is set to SingleUnifiedPointer
- UI Image batching breaks when interleaving elements with mixed z-positions and materials
- KeyNotFoundException is thrown when retrieving some values from HyperLinkClickedEventArgs
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.