Search Issue Tracker

Won't Fix



Found in



Issue ID




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()'
Rolloff:ChangeRolloff() (at Assets/Audio Manager/Rolloff.cs:47)

Cannot reproduce with: 2019.1.0a10 and 2018.3.1f1
Reproducible with: 2019.1.0a11 and 2019.2.0a1

  1. 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.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.