Separate `DepthRenderer`s not created for `Camera`s with the same name

According to this part of the Babylon.js source, new DepthRenderer()is only created for every Camera with a unique name.

I have the (bad?) habit of not naming any Babylon objects (leaving the names as empty ‘’ strings). This caused 2 cameras to share a DepthRenderer, which caused SelectionOutlineLayer to sometimes not or partially render when swapping cameras.

Please see the video below where outlines render well with the player’s ArcRotateCamera, but switching to a FreeCamera causes outline rendering issues.

I simply solved this by giving both cameras unique names.

I was wondering if it would be preferable to create new DepthRenderer()for every Camera regardless of their names?

I agree, using the name as key is error prone. I also got bitten by this a few months ago :laughing:

Thanks for the report (and the clear repro video)!

You’re right that this is error-prone. The internal Scene._depthRenderer dictionary was keyed by camera.id, and since Node.id falls back to name, two unnamed cameras end up colliding on “” and sharing a single DepthRenderer — which is exactly what’s causing your SelectionOutlineLayer issue when switching cameras.

I just opened a PR that switches the key from camera.id to camera.uniqueId (which is guaranteed unique per Camera instance): fix(depthRenderer): key Scene._depthRenderer by camera.uniqueId instead of camera.id by Popov72 · Pull Request #18384 · BabylonJS/Babylon.js · GitHub

Each camera will now get its own DepthRenderer regardless of name/id, so the workaround of giving them unique names won’t be needed once this is merged.

Thank you so much, Evgeni! :smile: