However, if I try to move them from one group to another (like in an object sorting game) this often happens:
The only way to fix this is to add another icon, or change the screen size by double-clicking the game window tab. The code that moves the icon is this:
These seem to make the x or y position of the container go absolutely wild. The position will rapidly increase forever, even outside playmode. I’ve tried them many times, but something seems broken.
I think you don’t want those ForceChildExpand boxes checked.
These Layout controller thingies are a little bit “thenthitive” to fiddle with. It seems every time I go to use one I have to relearn it. I recommend making a blank scene and just go nuts making these things again and again, inserting items into them, trying the different options, etc.
The other thing is to make sure your anchoring is correct and to know that the layout thingy WILL control your children objects in various ways: you’ll see various parts of the RectTransforms of children grayed out.
Generally when any of the UI stuff malfunctions spectacularly, I sniff around to see if I can figure out where it went wrong, then I just delete it and recreate it.
One thing that can really bork things is if you ever set a scale (or any part of a scale) to zero. If you animate something to vanish by scale zero, or if you hide something by scale zero, you can explode all kinds of stuff, and if you save the scene in that state, you may be very sad.
Oh no. I use zero all the time. It may be why… So I can’t hide things by shrinking them at all? Or is it okay if I do new Vector3(0.0001, 0.0001, 0.0001) or similar? Or does z always have to be 1?
How do you feel about using LayoutRebuilder.MarkLayoutForRebuild(layoutGroupTransform.GetComponent<RectTransform>()); to fix the weird issues? It seems to work tbh.
Hi the Canvas scaler and the horizontal layout group should work together to keep all UI elements in line with minimal coding.
so make sure you have tuned them correctly.
I like to make a canvas, make handles and the like, things I could parent to, and make it so I can switch aspects and resolutions and it gives me a close or exact match for a usable UI. It kicks you if you forget about it. And can feel buggy to work with. But the layout groups, layout elements and canvas scaler component along with correct parenting should handle all of the issues nicely in the end.
The second link was helpful generally, thank you, but I’m still not sure what the best thing to do regarding size of UI elements is. Is there a minimum acceptable size? Or should I avoid minimising them entirely?