Skip to content

0.17.3 Sprite picking behaves weird with more than one camera #22366

@guysv

Description

@guysv

Bevy version and features

  • 0.17.3
  • --features custom_cursor
AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

What I did

In my game, I:

  1. had a custom cursor
  2. used sprite picking (i.e. click observers on sprites)
  3. had multiple cameras

Apparently, this deadly combo disables sprite picking, if the multiple cameras are spawned in certain order.
I made a demo to show it:

https://github.com/guysv/bevy/blob/e55d756b7c70fffa331f1f6fb97f51ae03d2788a/examples/window/custom_cursor_image.rs

run with

ENABLE_CUSTOM_CURSOR_AT_STARTUP=1 SPAWN_MINIMAP_CAMERA_AT_STARTUP=1 cargo run --example custom_cursor_image --features custom_cursor

(from this revision of my fork: e55d756b7c70fffa331f1f6fb97f51ae03d2788a)
the commit after it is coding agent proposed fix where I investigated the issue

What went wrong

  • if custom cursor is enabled and "minimap"(=second camera) is enabled, clicking on the sprite at the middle of the screen doesn't work until we disable the second camera ('C' key).
  • if we respawn the second camera, sprite clicking is broken again

if either env vars in the command are missing, the example is working properly.

Additional information

coding agent proposed fix
guysv@5c36720

I see bevy 0.18 rc already has a different implementation there. maybe they avoid the bug?

WORKAROUND

to trick the find() call the fix removes, you can try to change the order you spawn cameras in your app. appears to make it work but it's undocumented so kinda scary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-PickingPointing at and selecting objects of all sortsC-BugAn unexpected or incorrect behaviorD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions