Destroying a gameobject on Awake - EventSystem error in B-20

I am destroying some gameobjects on Awake based on some settings. This result in following repeated error and all ui elements stop responding to events:

MissingReferenceException: The object of type ‘Image’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Component.GetComponent[CanvasRenderer] ()
UnityEngine.UI.Graphic.get_canvasRenderer () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Graphic.cs:193)
UnityEngine.UI.Graphic.get_depth () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Graphic.cs:154)
UnityEngine.UI.GraphicRaycaster.Raycast (UnityEngine.Canvas canvas, UnityEngine.Camera eventCamera, Vector2 pointerPosition, System.Collections.Generic.List1 results) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/GraphicRaycaster.cs:180) UnityEngine.UI.GraphicRaycaster.Raycast (UnityEngine.EventSystems.PointerEventData eventData, System.Collections.Generic.List1 resultAppendList) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/GraphicRaycaster.cs:104)
UnityEngine.EventSystems.EventSystem.RaycastAll (UnityEngine.EventSystems.PointerEventData eventData, System.Collections.Generic.List`1 raycastResults) (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/EventSystem.cs:134)
UnityEngine.EventSystems.PointerInputModule.GetMousePointerEventData () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/InputModules/PointerInputModule.cs:145)
UnityEngine.EventSystems.StandaloneInputModule.ProcessMouseEvent () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/InputModules/StandaloneInputModule.cs:276)
UnityEngine.EventSystems.StandaloneInputModule.Process () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/InputModules/StandaloneInputModule.cs:159)
UnityEngine.EventSystems.EventSystem.Update () (at /Applications/buildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/EventSystem.cs:228)

1 Like

We have fixed this internally and it will be in the next release.

thanks

I’m using Beta 21 and have the same issue. It happens when I try to remove elements from the UI.

This piece of code causes the issue as highlighted in the thread above

Transform child = optionsPanel.transform.GetChild(0);
child.parent = null;
GameObject.Destroy(child.gameObject);

This piece of code crashes unity

Transform child = optionsPanel.transform.GetChild(0);
GameObject.Destroy(child.gameObject);

I’m currently just unparenting my child control until the issue is fixed. At least my console isn’t flooded anymore. This means the element is parentless so leaking into the game object list.

Transform child = optionsPanel.transform.GetChild(0);
GameObject.Destroy(child);

Looking forward to the next update