Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'UGUI & TextMesh Pro' started by mog-mog-mog, Oct 23, 2014.

  1. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    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.List`1 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.List`1 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)
     
    nventimiglia likes this.
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    We have fixed this internally and it will be in the next release.
     
  3. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
  4. ReynV

    ReynV

    Joined:
    Sep 24, 2014
    Posts:
    50
    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
    Code (CSharp):
    1. Transform child = optionsPanel.transform.GetChild(0);
    2. child.parent = null;
    3. GameObject.Destroy(child.gameObject);
    This piece of code crashes unity
    Code (CSharp):
    1. Transform child = optionsPanel.transform.GetChild(0);
    2. 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.
    Code (CSharp):
    1. Transform child = optionsPanel.transform.GetChild(0);
    2. GameObject.Destroy(child);
    Looking forward to the next update