Skip to content

Add RenderLayers support to picking backend#124

Open
lukeod wants to merge 1 commit into
bytestring-net:mainfrom
lukeod:fix/proper-renderlayers-picking2
Open

Add RenderLayers support to picking backend#124
lukeod wants to merge 1 commit into
bytestring-net:mainfrom
lukeod:fix/proper-renderlayers-picking2

Conversation

@lukeod

@lukeod lukeod commented Oct 30, 2025

Copy link
Copy Markdown

Summary

Adds RenderLayers support to the Lunex picking backend to properly filter entities and cameras by visibility layers.

Problem

The picking backend was not respecting RenderLayers, causing UI elements to receive pick events from cameras that shouldn't be able to see them. This is particularly problematic in multi-camera setups where different cameras target different layers (e.g., a 3D
world camera on layer 0 and a 2D UI camera on layer 1).

Solution

  • Added Option<&RenderLayers> to both camera and entity queries
  • Filter entities by RenderLayers intersection with the active camera
  • Select the highest-order active camera using max_by_key() instead of find()
  • Default to DEFAULT_LAYERS (layer 0) for entities/cameras without explicit RenderLayers

Changes

  • Camera selection now prioritizes the highest-order camera when multiple cameras target the same pointer
  • Entities are only pickable by cameras that share at least one RenderLayer
  • Maintains backward compatibility with existing code that doesn't use RenderLayers

Testing

Tested with a multi-camera setup:

  • 3D world camera (order 0, layer 0)
  • 2D UI camera (order 1, layer 1)
  • UI elements correctly picked only by UI camera
  • Works correctly when either camera is disabled

Related

Follows the same pattern as Bevy's built-in mesh picking backend for RenderLayers filtering.

This is the same issue identified by PR #108, however this commit aims to follow bevy norms, and not implement any breaking changes (such as requiring an explicit camera index).

- Filter cameras and entities by RenderLayers intersection
- Select highest-order active camera for pointer target
- Maintains compatibility with entities without RenderLayers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant