Store UI render target info locally per node#17579
Merged
alice-i-cecile merged 95 commits intobevyengine:mainfrom Feb 10, 2025
Merged
Store UI render target info locally per node#17579alice-i-cecile merged 95 commits intobevyengine:mainfrom
alice-i-cecile merged 95 commits intobevyengine:mainfrom
Conversation
Change `update_target_camera_system` to update the `ResolvedCameraCamera` components.
Renamed `NodeScaleFactor` -> `ResolvedScaleFactor`
Co-authored-by: UkoeHB <37489173+UkoeHB@users.noreply.github.com>
… into resolved-ui-context
Contributor
Author
Thanks for reviewing this. I agree, ran some benchmarks and I was definitely overestimating the benefits of more granular change detection. In practice changing the resolution or scale factor is almost always going to result in a full relayout of everything so there's no benefit to having the separate components. |
… into resolved-ui-context
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
This is much more sensible. I've left a suggestion for improved docs for the new component.
alice-i-cecile
approved these changes
Feb 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
It's difficult to understand or make changes to the UI systems because of how each system needs to individually track changes to scale factor, windows and camera targets in local hashmaps, particularly for new contributors. Any major change inevitably introduces new scale factor bugs.
Instead of per-system resolution we can resolve the camera target info for all UI nodes in a system at the start of
PostUpdateand then store it per-node in components that can be queried with change detection.Fixes #17613
Fixes #17578
Fixes #15143
Solution
Store the UI render target's data locally per node in a component that is updated in
PostUpdatebefore any other UI systems run.This component can be then be queried with change detection so that UI systems no longer need to have knowledge of cameras and windows and don't require fragile custom change detection solutions using local hashmaps.
Showcase
Compare
measure_text_systemfrom main (which has a bug the causes it to use the wrong scale factor when a node's camera target changes):with
measure_text_systemfrom this PR (which always uses the correct scale factor):Testing
I removed an alarming number of tests from the
layoutmodule but they were mostly to do with the deleted camera synchronisation logic. The remaining tests should all pass now.The most relevant examples are
multiple_windowsandsplit_screen, the behaviour of both should be unchanged from main.