Skip to content

Instantly share code, notes, and snippets.

@tigregalis
Created May 13, 2022 11:47
Show Gist options
  • Save tigregalis/d3c5afdde573abe07042cb74ac83207c to your computer and use it in GitHub Desktop.
Save tigregalis/d3c5afdde573abe07042cb74ac83207c to your computer and use it in GitHub Desktop.
bevy system for inspecting all entities and which components they have when pressing F1
use bevy::ecs::entity::Entities;
use bevy::ecs::archetype::Archetypes;
use bevy::ecs::component::Components;
fn inspect(
keyboard: Res<Input<KeyCode>>,
all_entities: Query<Entity>,
entities: &Entities,
archetypes: &Archetypes,
components: &Components,
) {
if keyboard.just_pressed(KeyCode::F1) {
for entity in all_entities.iter() {
println!("Entity: {:?}", entity);
if let Some(entity_location) = entities.get(entity) {
if let Some(archetype) = archetypes.get(entity_location.archetype_id) {
for component in archetype.components() {
if let Some(info) = components.get_info(component) {
println!(" {}", info.name());
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment