#Debugging bevy in rustrover & trying to display hitboxes as a debug command

5 messages · Page 1 of 1 (latest)

signal sail
#

Hi, Been trying to display the bounding boxes of my entities tagged with Debuggable. The query itself seems to fetch them, and when i add children (supposedly a red box?) nothing happens, the hitbox_q counter goes up for each time i try to apply them, but they're not removed nor visible.

Side quest: I get this error when i try to run the debugger in rostrover to inspect whats going on. How do i handle this?

Here's the debug plugin

fn build(app: &mut App) {
        app.add_plugins(FpsOverlayPlugin {
            config: FpsOverlayConfig {
                text_config: TextFont {
                    font_size: 22.0,
                    font: default(),
                    font_smoothing: FontSmoothing::default(),
                },
                text_color: OverlayColor::GREEN,
                enabled: true,
            }
        })
            .add_systems(Update, customize_config);
    }

fn customize_config(
    mut commands: Commands,
    input: Res<ButtonInput<KeyCode>>,
    mut overlay: ResMut<FpsOverlayConfig>,
    debug_q: Query<(Entity, &Transform), With<Debuggable>>,
    hitbox_q: Query<Entity, With<Hitbox>>,
) {
    if input.just_pressed(KeyCode::Digit1) {
        overlay.enabled = !overlay.enabled;
    }
    if input.just_pressed(KeyCode::Digit2) {
        for (entity, transform) in debug_q.iter() {
            let has_hitbox = hitbox_q.get(entity).is_ok();

            if has_hitbox {
                if let Ok(child) = hitbox_q.get(entity) {
                    commands.entity(entity).despawn();
                }
            } else {
                commands.entity(entity).with_child((
                    Sprite {
                        color: Color::srgba(1.0, 0.0, 0.0, 0.5),
                        custom_size: Some(Vec2::new(transform.scale.x, transform.scale.y)),
                        ..default()
                    },
                    Hitbox
                ));
            }
        }
    }
}```
Bird is defined like this: 
```rs
fn spawn_player(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn((
        Bird::default(),
        Sprite {
            image: asset_server.load("bird.png"),
            ..default()
        },
        Transform {
            translation: Vec3::new(300., 450., 0.),
            ..default()
        },
        Debuggable,
    ));
}``` (Bird is just speed & rotation floats)
atomic spire
#

You are using transform.scale in the size of the box. This is not the sprite size. That value is most likely 1.0 so you are getting 1x1 box.

signal sail
#

I completely missed i got a response, sorry.
How do i work with the size of the sprite? I was hitting my head a bit on that.

atomic spire
#

You can either save the size in some component yourself for easy access, or you can query image assets with the handle from sprite to get image information from there

#

I'm on my phone right now so I can't give you examples.