Use RayMap and RenderLayers in bevy_sprite/picking_backend #21959
+150
−115
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.
Credit
Objective
Solution
bevy_sprite/picking_backend.rs. It now iterates over bevy_picking'sRayMapto generatePointerHits for each viableCamera, rather than just the first viableCamerafound.Camera's andSprite'sRenderLayersintersect before generating a hit.Testing
What reviewers can test
PointerHits would not generate on viewports of higher order, if their area overlapped with a viewport of lower order. For example, if you had aCamerarender to the entire window, and then a secondCamerarender a smaller viewport on top, the smaller viewport would not detectPointerHits. This should be fixed now.Cameranot on the defaultRenderLayerslayer, would generate and consumePointerHits, even if it did not share any layers with the pickedSprites. This could also blockSprites 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 aSpriteyou 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?