[SOLVED] Content Size Fitter Without Layout Group?

Hi

Content size fitter only works with a Layout Group, however I have content that is manually placed and does not require a vertical, horizontal or grid layout.

Is it possible to get my parent panel to resize to the manually placed children without using a script?

Example:

Thanks in advance

I’ve had this question in the past. I came to the conclusion that the assumption is that if you are manually placing your children then the panel should be static as well as the children in which case you can set that panel size in the editor. If you are dynamically changing the position or scale of your children with a script then you can simply change the parent panel with the same script. IE change the panel size to desired, then change the children based on new panel size. It gets a bit tricky if your moving a child in world space but basically you would allow the child to be dragged within the contents of the panel, if the child hits the edge or buffered edge of the panel, clamp it and switch the drag to scale the panel instead. As far as I know, what your asking is not possible without a script however I am not an expert at the new UI.

EDIT: btw I would love a content fitter that expanded / contracted a panel based on the position of its children without a layout group like what your asking for in case any devs read this :wink:

1 Like

In my case, the parent panel will dynamically change it’s height based on the children’s height and position, which includes text, buttons and images.

I know I can take some sort of script based approach, I was just seeing if it’s possible to do it with the available Unity UI scripts.

Basically I need this for a chat app. The Text objects are children (among other child objects) that could have different lengths, which means the parent needs to adapt it’s height for the Text.

But if the child objects are manually placed, you can manually change the container size at the same time. Right?

Are you asking for an in-editor tool which will do this recalculation for you?

They are manually placed but can themselves dynamically change their height, which means the parent needs to as well.

[SOLUTION]
I have solved this issue by attaching the “Layout Element” to all objects that do NOT dynamically change their height and toggling the setting “Ignore Layout” to on. This way, I CAN put a layout group and content size fitter on the parent and only the dynamically changing child will be affected. BOOM.

10 Likes

@enchiridion
Congratulations! I was so happy when I found that feature, I didn’t realize that’s what you were looking for.

My good sir, you are a GENIUS!!!