Hi, I experienced a strange behaviour after updating to b20. After upgrading a dynamically populated GridLayoutgroup inside of a ScrollRect is causing a MissingReferenceException, which I am unable to fix: The error is caused by the EventSystem. If I remove the EventSystem out of the Hierarchy all is running fine (except that no events fire). I'd file this as a bug, but my project is already 1.1GB and I cannot reproduce this error in a newly created project :-( Perhaps someone else got an idea what is causing this to happen. (at the time the error occurs all images are loaded and displayed without any problems - it's just the event system completely messing up. As you can see in the stacktrace, no custom script is involved) Code (csharp): 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] () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineComponent.cs:189) UnityEngine.UI.Graphic.get_canvasRenderer () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/UI/Core/Graphic.cs:193) UnityEngine.UI.Graphic.get_depth () (at C:/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 C:/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 C:/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 C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/EventSystem.cs:134) UnityEngine.EventSystems.PointerInputModule.GetMousePointerEventData () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/InputModules/PointerInputModule.cs:145) UnityEngine.EventSystems.StandaloneInputModule.ProcessMouseEvent () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/InputModules/StandaloneInputModule.cs:276) UnityEngine.EventSystems.StandaloneInputModule.Process () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/InputModules/StandaloneInputModule.cs:159) UnityEngine.EventSystems.EventSystem.Update () (at C:/BuildAgent/work/d63dfc6385190b60/Extensions/guisystem/guisystem/EventSystem/EventSystem.cs:228) EDIT: the exceptions are only fired while the game window is active. (App.runInBackground is true) There's no error or exception in the population process of the list any help is greatly appreciated
I am having the same issue. I have a hierachy of views (canvas renderers with child controls) that I'm going through, which works fine - when switching views I instantiate the new one and then destroy the old one. But after transitioning between one of these views to the next I keep getting this exception as well. This seems fairly random; going from view 1, 2, 3 works great, then I hit view number 4 and this happens. It's as if the event system is trying to keep raycasting against controls that no longer exist - but then why doesn't it throw these exceptions every time I Destroy a UI object?
this is a good hint into the right direction. My List contains 2 entries in the editor view, which I use for editing the prefabs. On Runtime, these entries are removed and the list is repolulated. If I comment out the code which empties the list the exception does not occur. Maybe it's the wrong way to clear the list Code (CSharp): RectTransform[] existingElements = panel.GetComponentsInChildren<RectTransform> (); for (int j =0; j< existingElements.Length; j++) { if (existingElements [j].gameObject.name == panel.name) { continue; } if (existingElements [j].gameObject != null) { GameObject.Destroy (existingElements [j].gameObject); } }
OK, I seem to have solved my instance of the issue in an unexpected way. One of the controls on the view that was causing the exception after being deleted, was a button that I set inactive by default: Code (CSharp): void Awake() { SwitchCameraButton.gameObject.SetActive(false); } However, if I disable the button in Start() instead of Awake(), I don't get any exceptions when I Destroy it. It seems the Image component or its object needs to be active at Awake-time in order for the event system to handle it properly. This workaround seems to fix my case for now: Code (CSharp): void Awake() { SwitchCameraButton.gameObject.SetActive(true); } void Start() { SwitchCameraButton.gameObject.SetActive(false); } @Unity GUI team: is this normal behavior, or a bug? Or is there a better way altogether to completely hide UI controls so I can avoid using SetActive() ? @vrm2p: does this apply to your case as well? Can't say for sure, it would depend on how and when you populate your ScrollRect I guess.
This seem to be 2 completely different bugs leading to the same result. I don't have any disabled controls (non-interactable, but not disabled) EventSystem.RaycastAll seems to find already deleted objects, that are not completely removed. Edit: still cannot reproduce in a demoproject :-(
Had the same issue after updating to b20. I have a ScrollView with a Grid Layout Group as the content. Whenever I empty the Grid Layout Group, I get the same exception as the op. Managed to work around this issue by calling GraphicRegistry.UnregisterGraphicForCanvas on each Image component before destroying the Grid Layout Group's children.
I've got a project that repro's it, though the steps to get to the repro are a bit arcane, I'll send it through and get back with the number once it arrives
Hey I fixed this problem by making sure gameObject.SetActive(false); before Destroying it. I think setting it to inactive effectively removes it from the EventSystem.