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

Despawn/Remove Functionality #36

Open
lanesawyer opened this issue Jan 29, 2024 · 2 comments
Open

Despawn/Remove Functionality #36

lanesawyer opened this issue Jan 29, 2024 · 2 comments

Comments

@lanesawyer
Copy link

lanesawyer commented Jan 29, 2024

Hey there, been playing with bevy-parallax today and ran into a problem: I can't manage to remove the parallax!

This may be me being awful at Bevy and not a problem with the library itself, so if that's the case I apologize in advance.

My setup has different game states (Menu, Game), and I only want the parallax drawn when I'm in Game state. I only have one camera for the various states, so I can't simply throw away the camera entirely like some of the examples in this repository do to reset the parallax.

Here's how I'm initializing it:

fn initialize_parallax(
    mut commands: Commands,
    mut create_parallax: EventWriter<CreateParallaxEvent>,
    camera_query: Query<Entity, With<MainCamera>>,
) {
    let camera = camera_query.get_single().expect("Camera not found");
    commands.entity(camera).insert(ParallaxCameraComponent::default());

    create_parallax.send(CreateParallaxEvent {
        // ... the layers_data,
        camera
    });

I tried to remove the ParallaxCameraComponent from the camera when leaving the Game game state, but that isn't working:

fn despawn_parallax(
    mut commands: Commands,
    camera_query: Query<Entity, With<MainCamera>>,
) {
    for entity in &mut camera_query.iter() {
        commands.entity(entity).remove::<ParallaxCameraComponent>();
    }
}

Is this a valid use case for bevy-parallax adding some sort of remove/despawn command added in future versions, or am I just doing it wrong?

@evaogbe
Copy link

evaogbe commented Aug 18, 2024

I'm not sure if this is right, but I got it to work by removing the LayerComponent.

fn cleanup_background(mut commands: Commands, layer_query: Query<Entity, With<LayerComponent>>) {
    for entity in &layer_query {
        commands.entity(entity).despawn_recursive();
    }
}

@lanesawyer
Copy link
Author

Sweet, I'll give that a go. Thank you!

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

No branches or pull requests

2 participants