Search Unity

ContentSizeFitter doesnt adjust automatically

Discussion in 'Editor & General Support' started by AllanSmithZ3, Aug 8, 2019.

  1. AllanSmithZ3

    AllanSmithZ3

    Joined:
    May 21, 2019
    Posts:
    23
    Hey,

    I believe in every single game I've worked on to this day (since Unity UI was added), I ran into this problem. Basically if your hierarchy is somewhat complex, with parents depending on children, and children depending on grand children for size for example, and you change the number of grand children while everything is disabled or invisible cause you want to hide the "repopulation" of said hierarchy, when you turn it back on, the original parent does not adjust properly with the new size of its children, maybe due to optimizations, maybe cause it doesnt do it recursively to save performance... and that is fine... but I've tried all the recommended methods, Layout.ForceResize, Layout.MarkForResize (sorry I even forgot the real name of the methods), and even Canvas.ForceRebuildEverything, and calling them is useless because when they run their calculations, everything is still disabled, invisible, so they are like "sure, let me recalculate" and they get the same result... which ends up with me having to fix with a dirty hack like a coroutine to wait a couple frames to call MarkForRecalculation, and then it works... so while there is a work around, it would be great to have a "force recalculate considering disabled children" or whatever it might be that prevents it from working.

    I guess the point of this post other than a small rant is, how do you solve this issue, have you had it before? Do you use a similar dirty hack or did you find a proper way to do it?

    Best,
    Allan