4.6 UI.System: Triggering Layout Rebuild help

Hello community!

Copied from the manual’s documentation on recalculating the Auto Layout of the UI system, by using the LayoutRebuilder.MarkLayoutForRebuild (transform as RectTransform) function:

“The rebuild will not happen
immediately, but at the end of the
current frame, just before rendering
happens.”

From this instruction only, I assume that I have to wait for the next frame, so that the current modifications in the layout’s properties will take effect and therefore to be possible to consider them in new calculations. With this assumption I have been using a yield instruction right after I have called the Rebuild function. Am I correct so far?

There is a visual side effect of using the yield coroutine, however. Given that the layout changes are applied within a number of frames by the end of each one the graphics are also calculated, the result is an animation effect of the changes. Although in my case it is not a bad contribution (rather the opposite), I was wondering on one hand, if I even approach the whole thing correctly and, on the other, what can be done if this animation effect is not desired. Is there even a way to move to the next frame, without having the graphics of the particular objects updated, until we want this to happen (in this case, after the layout changes have been applied)?

Thanks in advance for any help. Since the UI system is relatively new there are not many examples around (especially regarding run time GUI development) from which I can get ideas and solutions.

I am not sure, if I didn’t make my problem clear or it is true I guess that not many exploration in the world of the new UI is done and even if this might be an issue of a more general nature, I will contribute my finding, even though I’m not sure, if it is totally correct.

So my main concern had been to remove the yield statement and still have the layout of the controls updated, before the end of the frame. I found out that by calling the Canvas.ForceUpdateCanvases() function instead, I get the desired result. I haven’t done a lot of testing and I don’t know if it’s the most efficient solution or better yet if my whole approach is good, but I will rest with that for the time being.

Also check out UIBehaviour.OnRectTransformDimensionsChange() which invokes when its RectTransform’s proportion changes during a layout. This sometimes works when Canvas.ForceUpdateCanvases() doesn’t. Coroutine is the last resort.