komadori / bevy_mod_outline

Apache License 2.0
123 stars 10 forks source link

Repeatedly inserting OutlineBundle makes it disappear #18

Closed rMazeiks closed 1 year ago

rMazeiks commented 1 year ago

Hiya! Thanks for the amazing crate!

I found a bug that makes the outline effect disappear if the OutlineBundle is inserted again (overwriting the original one).

Consider this code, adapted from one of the examples:

use bevy::prelude::{shape::Cube, *};

use bevy_mod_outline::*;

#[bevy_main]
fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(OutlinePlugin)
        .add_startup_system(setup)
        .add_system(overwrite_outline)
        .run();
}

fn overwrite_outline(query: Query<Entity, With<OutlineVolume>>, mut commands: Commands) {
    for entity in &query {
        commands.entity(entity).insert(OutlineBundle {
            outline: OutlineVolume {
                visible: true,
                colour: Color::ORANGE,
                width: 5.0,
            },
            ..default()
        });
    }
}

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    let mut cube_mesh = Mesh::from(Cube { size: 1.0 });
    cube_mesh.generate_outline_normals().unwrap();
    commands
        .spawn(PbrBundle {
            mesh: meshes.add(cube_mesh),
            material: materials.add(Color::GRAY.into()),
            ..default()
        })
        .insert(OutlineBundle {
            outline: OutlineVolume {
                visible: true,
                colour: Color::ORANGE,
                width: 5.0,
            },
            ..default()
        });

    commands.spawn(PointLightBundle {
        point_light: PointLight {
            intensity: 1500.0,
            ..default()
        },
        transform: Transform::from_xyz(4.0, 8.0, 4.0),
        ..default()
    });
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}

The outline correctly appears on the first frame, then disappears. It's as if inserting a new OutlineBundle to overwrite the existing one breaks the effect.

If we don't add the overwrite_outline system, the example works as expected (gray cube with orange outline)

I was expecting to be able to freely insert the outline bundle as many times as I like, and the effect to update accordingly. Surely this is a bug?

I can easily work around this, just thought you'd want to know about it.

komadori commented 1 year ago

Thank you for reporting this bug. The issue is that re-inserting OutlineBundle resets the state of the ComputedOutlineDepth component and this isn't detected in the propagation system. I've committed ac9ae75cef966119809cb54e828fda7f89f0dcbe to fix this and will make a new point release soon.

komadori commented 1 year ago

Released 0.4.2.

rMazeiks commented 1 year ago

Awesome; could not reproduce with 0.4.2 :tada:

Thanks again and congrats on the release!