LayoutRebuilder Does not fully rebuild complex parented layout groups

Hello World!

There is a feature in my project that essentially reads the scene objects’ hierarchy (which can be altered at will by the user to create very ellaborate constructs) and creates a 2D representation of said hierarchy in a special UI window.

Every item in the scene is represented in that window by an item that is itself a layout element and a vertical layout group with a content size fitter. That gives every item the ability to contain and represent as many other items as possible, along with their own children, as the panels stretch accordingly (this bit works).

However, the “LayoutRebuilder.ForceRebuildLayoutImmediate” function does not manage to properly set all items’ stretching correctly in a single pass, probably due to the nature of multiple layout groups parented inside each other. After being called once, some items will have stretched properly, but others will not. Calling the LayoutRebuilder multiple times does fix the matter, but since the parenting in the scene can “theorethically” be infinite, I cannot set a definite amount of times to call the LayoutRebuilder after building the window.

Does anyone know of a way to force the LayoutRebuilder to run until UI objects’ rectTransform no longer change from being updated or something similar? I could have a function that runs on every item in the window, but since they can be very numerous, it would slow the program down immensely…

(this all happens in C#)

Thank you in advance!

Failing a better understanding of Unity’s mechanisms, I’ve settled for a do/while loop that stores the uppermost scalable parent of the hierarchy’s sizeDelda values and compares them to its new values after each LayoutRebuilder pass, and drops when the stored and actual values are identical.

If there’s a better way of doing things, I remain ignorant of it…