Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to choose the default ui camera #11377

Closed
pablo-lua opened this issue Jan 16, 2024 · 2 comments · Fixed by #11436
Closed

Allow user to choose the default ui camera #11377

pablo-lua opened this issue Jan 16, 2024 · 2 comments · Fixed by #11436
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use
Milestone

Comments

@pablo-lua
Copy link
Contributor

pablo-lua commented Jan 16, 2024

What problem does this solve or what need does it fill?

There is an example of a problem that this can lead in #11237, where we cannot spawn a new Camera in the same window as primary window without possible problems appearing (Debug camera interpolating with Ui camera)

What solution would you like?

  • The creation of a marker Component DefaultUiCamera (or a similar name: This name is already in use and can lead to conflicts), so when selecting the camera with a root entity that doesn't have TargetCamera, the DefaultCamera param will give priority to this component.

What alternative(s) have you considered?

  • The user, when creating a camera for debug purposes (Or another purposes that for now I don't know if exists), will have to add an TargetCamera for each root that exists (even though only one camera will load the Ui, the other Camera is created for another purposes) (This option Don't need the API Refactor)
  • Return with the UiCameraOptions, an component that marks if the Camera should show ui or not (I think we don't need this anymore)

Aditional Context

  • For now, say that you have two cameras spawned for PrimaryWindow -> The actual API will not return a warn or something, it will almost randomly pick one of the cameras. The camera depends on the camera order, the line is as follow:
    cameras: Query<'w, 's, (Entity, &'static Camera)>,

///...
self.cameras
    .iter()
    .filter(|(_, c)| match c.target {
        RenderTarget::Window(WindowRef::Primary) => true,
        RenderTarget::Window(WindowRef::Entity(w)) => self.primary_window.get(w).is_ok(),
        _ => false,
    })
    .max_by_key(|(e, c)| (c.order, *e))
    .map(|(e, _)| e)

but using the order can conflict if the user is building an debug camera (That generally will be above others)

@pablo-lua pablo-lua added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jan 16, 2024
@alice-i-cecile alice-i-cecile added A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jan 18, 2024
@alice-i-cecile alice-i-cecile added this to the 0.13 milestone Jan 18, 2024
@nicoburns
Copy link
Contributor

Could this also be fixed by not having a default ui camera at all? I feel like it might lead to a clearer, more explicit API if you just always need to declare a camera for each UI root.

@pablo-lua
Copy link
Contributor Author

I was aware of this approach, but if the TargetCamera is a required component (you Always have to declare it in the root), so we might as well put it in the NodeBundle or in other Bundles just so the User never forget to put this Component.
I really think that its ok to have a DefaultCamera though

github-merge-queue bot pushed a commit that referenced this issue Jan 27, 2024
# Objective

- Resolves #11377 

## Solution

- Add marker component `IsDefaultUiCamera` that will be choosen first as
the default camera.

If you want the IsDefaultUiCamera default camera to be in another
window, thats now possible.
- `IsDefaultUiCamera` is expected to be within a single Camera, if that
assertion fails, one PrimaryWindow Camera will be choosen.

---

## Changelog

### Added
- Added `IsDefaultUiCamera` marker component.

---------

Co-authored-by: Mateusz Wachowiak <[email protected]>
tjamaan pushed a commit to tjamaan/bevy that referenced this issue Feb 6, 2024
# Objective

- Resolves bevyengine#11377 

## Solution

- Add marker component `IsDefaultUiCamera` that will be choosen first as
the default camera.

If you want the IsDefaultUiCamera default camera to be in another
window, thats now possible.
- `IsDefaultUiCamera` is expected to be within a single Camera, if that
assertion fails, one PrimaryWindow Camera will be choosen.

---

## Changelog

### Added
- Added `IsDefaultUiCamera` marker component.

---------

Co-authored-by: Mateusz Wachowiak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants