Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RenderLayers does not affect SceneBundle #5183

Open
ostwilkens opened this issue Jul 3, 2022 · 7 comments
Open

RenderLayers does not affect SceneBundle #5183

ostwilkens opened this issue Jul 3, 2022 · 7 comments
Labels
A-Hierarchy Parent-child entity hierarchies A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible

Comments

@ostwilkens
Copy link
Contributor

Bevy version

Latest bevy git commit at time of writing, 8f721d8d0ac2e14a46051175f6d3394ed87c7214.

Relevant system information

`AdapterInfo { name: "NVIDIA GeForce RTX 2070", vendor: 4318, device: 7938, device_type: DiscreteGpu, backend: Vulkan }`

What you did

I noticed this issue in my current project. I also tried adding the component RenderLayers::layer(1) to the SceneBundle in the split_screen example.

What went wrong

The component has no effect.

@ostwilkens ostwilkens added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jul 3, 2022
@tim-blackbird
Copy link
Contributor

tim-blackbird commented Jul 3, 2022

RenderLayers only applies to the entity it is on, it does not (currently) apply to children of that entity.

@ostwilkens
Copy link
Contributor Author

RenderLayers only applies to the entity it is on, it does not (currently) apply to children of that entity.

I see! It probably should though, right? In that sense I guess this is a feature request.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen A-Hierarchy Parent-child entity hierarchies C-Feature A new feature, making something new possible and removed S-Needs-Triage This issue needs to be labelled C-Bug An unexpected or incorrect behavior labels Jul 4, 2022
@alice-i-cecile
Copy link
Member

Related to #838. This is effectively the same feature, but for render layers.

@ostwilkens
Copy link
Contributor Author

Related to #838. This is effectively the same feature, but for render layers.

Oh yeah!
Though I would expect RenderLayers to be overrideable by a child.

@asafigan
Copy link
Contributor

asafigan commented Sep 1, 2022

I would like to propose a similar pattern to Visibility. Having a ComputedRenderLayers which is used to propagate the render layer down to children. Adding RenderLayers to a component will override this propagation and start a new propagation. The question is if this should be added to SpatialBundle and all related bundles or added dynamically by a system to call children of a entity with a RenderLayers component.

@dmlary
Copy link
Contributor

dmlary commented May 20, 2023

Awful brute-force workaround for this issue. Add a PropagateRenderLayers component, then a few systems to copy the RenderLayers component down to child entities for any entity with PropagateRenderLayers.

#[derive(Component)]
struct PropagateRenderLayers;

fn propagate_render_layers_added(
    mut cmds: Commands,
    parents: Query<(&RenderLayers, &Children), (Added<PropagateRenderLayers>, With<Children>)>,
) {
    for (render_layers, children) in &parents {
        for child in children {
            cmds.entity(*child)
                .insert((PropagateRenderLayers, *render_layers));
        }
    }
}

fn propagate_render_layers_changed(
    mut cmds: Commands,
    parents: Query<
        (&RenderLayers, &Children),
        (
            With<PropagateRenderLayers>,
            With<Children>,
            Changed<RenderLayers>,
        ),
    >,
) {
    for (render_layers, children) in &parents {
        for child in children {
            cmds.entity(*child)
                .insert(*render_layers);
        }
    }
}

fn propagate_render_layers_add_child(
    mut cmds: Commands,
    parents: Query<(&RenderLayers, &Children), (With<PropagateRenderLayers>, Changed<Children>)>,
) {
    for (render_layers, children) in &parents {
        for child in children {
            cmds.entity(*child)
                .insert((PropagateRenderLayers, *render_layers));
        }
    }
}

@dmlary
Copy link
Contributor

dmlary commented May 20, 2023

Or just use https://github.com/nicopap/bevy-scene-hook, which is much better than my workaround above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Hierarchy Parent-child entity hierarchies A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

5 participants