We are currently developing a game that include a coding scratch-like interface (a visual coding interface).
This visual coding interface is based on the Unity UI, layouts and content size fitter. However, when we remove a bloc from another one (ie: changing its parent), the UI breaks. We corrected it thanks to “ForceRebuildLayoutImmediate” and " ForceUpdateCanvases" but still, when Layouts are nested with 4 or 5 levels, the UI still breaks.
You can see it by yourself in action by playing the game for free here
At this point we don’t have any more ideas and we are starting to think it was a bad idea to use the Unity UI. Any help would be great
I see. Can you share a bit more info on how you set up the layout groups and content size fitters? Or (ideally) can you reproduce the behavior in a new project and maybe share it with us so we can have a look at the code? (it is hard to tell just from the screenshots)
You’re right, it’s hard to tell without seeing. The problem is that it would take days to extract this part from the project since everything is dynamic.
In this example I have 2 blocks attached with each other. The structure of a block is:
Bloc
BG
Block specific component and data
Next Block
The important thing is that the “Next” object size and other objects sizes are defined by its children thanks to the ContentSizeFitter component.
Basically, every object have a LayoutElement to have a minimal size, a Layout to order children and a ContentSizeFitter with the 2 parameters set to PreferredSize.
So here is what happen when I remove the block in the Next object:
The refresh at the end happen when I tried to change the position of the object in the scene.
I tried to be more specific I can. Do you now have a nice picture of the situation?
Ok, I think I understand your problem.
Basically you don’t want to use ContentSizeFitter in nested LayoutGroups.
I attached a small unitypackage with a setup example for nested VerticalLayoutGroups.