Language

When does the UI system generate its list of draw commands?

There is (as of Unity 5.6 beta) an issue where UI elements attached to SteamVR controllers lag behind the controllers by a frame. This appears to be because the controllers' positions are updated right at the point of rendering in the OnPreCull phase.

Question is: when are the draw commands for the UI system generated?

Or to put it another way: What's the latest I can update a UI transform for it to still be drawn in the right place in a frame?

The documentation is unclear--it says that Canvas elements are drawn"after scene rendering" but that doesn't mean that's when the draw commands are generated. In fact, they obviously aren't, because other Mesh objects that are children of the SteamVR controller do get drawn in the right place.

(I should add that I can probably find a workaround for my specific problem--I'm just curious about the UI system).

1 Reply

Well, most parts of the UI system are open source. However the Canvas itself is a built-in component. It has a private method called "SendWillRenderCanvases" which will actually trigger the update of all pending / dirty objects. Since this method is called internally by the engine itself we can't say for sure when it actually happens. We would have to do some testing to narrow it down, but that's something you can do on your own.

Btw: This method can be called manually by calling Canvas.ForceUpdateCanvases(). "ForceUpdateCanvases" is just a wrapper around "SendWillRenderCanvases()". So you can try just calling this after you did changes to your UI.