Skip to content

Conversation

@bloopyboop
Copy link

@bloopyboop bloopyboop commented Nov 27, 2025

Credit

  • @bytemunch for the original PR and the brunt of the work
  • @akimakinai for reviewing and introducing an important change to the RenderLayers logic

Objective

  • Adoption of the PR found here (as was recommended to me on the bevy discord)
  • I upgraded the changes proposed there to work with bevy/main
  • This likely fixes a bunch of unintuitive picking behavior around Viewports and RenderLayers. See the original PR for details.

Solution

  • Rewrote parts of bevy_sprite/picking_backend.rs. It now iterates over bevy_picking's RayMap to generate PointerHits for each viable Camera, rather than just the first viable Camera found.
  • Introduced checking if the Camera's and Sprite's RenderLayers intersect before generating a hit.

Testing

  • I tested it with my own game, running on bevy 0.17.3
  • I don't expect the behavior to be different for a game built with bevy/main, as it's just the picking backend. However, that is still open for testing.

What reviewers can test

  • Before this change, PointerHits would not generate on viewports of higher order, if their area overlapped with a viewport of lower order. For example, if you had a Camera render to the entire window, and then a second Camera render a smaller viewport on top, the smaller viewport would not detect PointerHits. This should be fixed now.
  • Before this change, a Camera not on the default RenderLayers layer, would generate and consume PointerHits, even if it did not share any layers with the picked Sprites. This could also block Sprites from being picked at all. This should be fixed now.

Extra note

The behavior of the picking backend is now to produce PointerHits for each viable viewport under the cursor. This can lead to the unintuitive result, that you can pick a Sprite you can not see, due to being obscured by another viewport.
I have a solution for this and it would be a flag in SpritePickingSettings. Should I open a new PR for this or enter a discussion?

@github-actions
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@bytemunch
Copy link
Contributor

Nice one :) I've been out the bevy loop a while, thanks for picking this up!

@dloukadakis dloukadakis added S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Picking Pointing at and selecting objects of all sorts C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Picking Pointing at and selecting objects of all sorts C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants