Scenario: I have a ResponsiveContainer with behaviour set to 'Fit Container To Content'.

Initially it has zero children, so its RectTransform Height is zero. For some reason the height of the container can't be manually edited in Editor (non-Play) mode to 10 or greater (it automatically resets to zero), possibly because I have all the margins/spacing set to zero?

In Play mode, if I instantiate a new ResponsiveItem gameobject and add it as a child of the container, the container won't resize to accomodate the new child. This happens even if I call Resize(true) on the container.

If, however, (in play mode) I manually adjust the container's height, as soon as it reaches 10 it suddenly behaves correctly ie resizes to a height which accommodates all its children.

Looking at the code, it's this bit that prevents the container being resized automatically during play mode:
if (ch < 10 || cw < 10)
return;

since the height is still zero at the time this code is called.

Would appreciate it if you could investigate this please.
Thank you!

    ledshok Hi,
    Allowing the container to have a width or height equal to 0 can lead to unexpected behaviours, so that's why the script is only working if the container is at least 10px width & height.

    About your issue, you're correct:
    If the container does not have children yet with this mode "fit to content" then its size will always be 0. Then if you add children afterward, it will not be working because of the condition you pointed out.

    can you try this instead ?

    if ((ch < 10 || cw < 10) && !force)
    return;

    then add you first child and call Resize(true) ?

    Thanks for reporting this bug, I will patch that for the next update!

    Anthony

      That works nicely. Thank you for the prompt support! 😃

      Write a Reply...