- Home /
When does canvas layout complete?
The case: We're populating the content area of a ScrollRect dynamically when constructing a particular page in the UI - that is, we have a list. The elements of this list have different heights, depending on the amount of content in a Text
component.
Timing considerations become important in two distinct cases:
When navigating to this view, we render it to a
RenderTexture
used in a transition animation. Here, we need to wait until layout is complete before actually rendering the view.When adding a new element to the list, we'd like to scroll to the bottom so that the user sees the addition. Again, setting the
normalizedVerticalPosition
to zero before the layout has completed results in it scrolling almost to the end of the list, but not quite.
The following questions arise:
We can request a relayout using
LayoutRebuilder
and/or registering a canvas element (the scroll rect) with theCanvasUpdateRegistry
. But when should we use which? Are there other mechanisms we should know about?According to the documentation, canvas layout is performed before rendering, at the end of the frame, and we've assumed that waiting in a coroutine with
WaitForEndOfFrame
should be sufficient to ensure a complete layout, but that doesn't always seem to be the case. Is there a way to get notified when layout has completed?
3 years later ... did you find any answers to your questions?
The official docs are still $$anonymous$$IA (I guess no-one at Unity can be bothered to write them), and LayoutRebuilder is still buggy, ... I could fix some of this if I could do basic actions like hooking "canvaslayout begins" (which I have some hacks for) and "canvas layout ends" (nothing seems to work)
Answer by steinjak · May 14, 2020 at 10:44 AM
Hi,
It's a long time since, so I don't I remember exactly, but I think we didn't find any answers - probably we found some kind of workaround, but I'm not sure. We've moved on from Unity since then. Sorry that I can't help...
-steinjak
Your answer
Follow this Question
Related Questions
Unity crashes when using ExecuteAlways on a UIBehaviour 0 Answers
Nested UI elements and layout 0 Answers
[UI] Grid Layout Group Custom Sort Order 1 Answer
How can I return a Dragged Object From a Layer Group to its Original Position? 0 Answers
How can I edit the horizontal layout group on a panel or object 1 Answer