Inconsistent UI canvas rendering on UI, in scene mode and game mode, and during game mode
Hi all, I'm trying to create a HorizontalLayoutGroup with LayoutElement inside at runtime by injecting my LayoutElement Prefab in the HorizontalLayoutGroup.
The problem is that often the LayoutElements are not displaying correctly side by side but some of them "jumps" 300/400px upper on the screen and they are overlapped, as the HorizontalLayoutGroup is not doing his job.
This happens both in scene mode and game mode.
In scene mode, if I reorder the hierarchy moving an element before another, this triggers some internal unity mechanisms and magically all the items starts display correctly.
In Game Mode, I run 'Canvas.ForceUpdateCanvases ();' and this solve the problem for many items but not everyone. Some are still in the wrong position. But if I resize the Game Scene by dragging the framing to expand or reduce it, the goes in the right place magically again.
I will now try to find a way to trigger the screen resize by code, if it exists.
By the way, I find all of this very frustrating, confusing and counterintuitive. Do anybody knows why this happens? I'm I the only? Is there a way to prevent this to happens or to fix it safely at run time?
I'm using Unity 5.6.1.f1.
Thanks.
Your answer
Follow this Question
Related Questions
Why LayoutGroup and LayoutElement has a RectTransform width? 1 Answer
How to keep panel inside scroll area when panel is shrunk? 0 Answers
Input Field inside a Scroll Rect doesn't resize the container. 1 Answer
How do I space out UI elements evenly in a horizontal layout group? 1 Answer
How do you add a material and change the size in Mesh Renderer in C# scripting? 1 Answer