GridLayoutGroup error when re-populating

Hey guys,

the first time I’m populating a GridLayoutGroup with game objects, everything’s fine.

However, at each subsequent try to add children to it after having it cleared, the following error is logged:

MissingReferenceException: The object of type 'RectTransform' 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.DrivenRectTransformTracker.Add (UnityEngine.Object driver, UnityEngine.RectTransform rectTransform, DrivenTransformProperties drivenProperties) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/RectTransformBindings.gen.cs:64)
UnityEngine.UI.GridLayoutGroup.SetCellsAlongAxis (Int32 axis) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/GridLayoutGroup.cs:115)
UnityEngine.UI.GridLayoutGroup.SetLayoutHorizontal () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/GridLayoutGroup.cs:92)
UnityEngine.UI.LayoutRebuilder.<Rebuild>m__9 (UnityEngine.Component e) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutRebuilder.cs:71)
UnityEngine.UI.LayoutRebuilder.PerformLayoutControl (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1 action) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutRebuilder.cs:103)
UnityEngine.UI.LayoutRebuilder.PerformLayoutControl (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1 action) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutRebuilder.cs:106)
UnityEngine.UI.LayoutRebuilder.PerformLayoutControl (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1 action) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutRebuilder.cs:106)
UnityEngine.UI.LayoutRebuilder.PerformLayoutControl (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1 action) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutRebuilder.cs:106)
UnityEngine.UI.LayoutRebuilder.Rebuild (CanvasUpdate executing) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutRebuilder.cs:71)
UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:122)
UnityEngine.Canvas:SendWillRenderCanvases()

It might be worth noting that the game object with the layout group is disabled and enabled in between.

We are using Unity 5.3.2p3.

Anyone else experiencing these issues?

I had this same issue with a vertical layout component.

In case someone else has this issue (since this about the only google search result on it) I fixed it by removing a Content Size Fitter off the vertical layout component’s parent.

3 Likes

Had exactly same problem :frowning: Probably have to create my own Content Size Fitter :frowning:

For all feature Googlers, who find this post. For me it was an AspectRatioFitter. And it wasn’t on the parent but on the anchestor 3 levels up.
@daretsuki Mind to share your own fitter? :wink: