Is it possible to get a list of components by having Entity in bevy rust? For example for debugging purposes.
use bevy::prelude::*;
fn main()
{
App::build()
.add_plugins(DefaultPlugins)
.add_startup_system(setup.system())
.add_system(first.system())
.add_system(first_no_second.system())
.add_system(first_and_second.system())
.run()
}
fn setup(mut commands: Commands)
{
commands.spawn().insert(FirstComponent(0.0));
commands.spawn().insert(FirstComponent(1.0));
commands.spawn().insert(SecondComponent::StateA);
commands.spawn().insert(SecondComponent::StateB);
commands.spawn().insert(SecondComponent::StateA).insert(FirstComponent(3.0));
commands.spawn().insert(SecondComponent::StateB).insert(FirstComponent(4.0));
}
#[derive(Debug)]
struct FirstComponent(f32);
#[derive(Debug)]
enum SecondComponent
{
StateA,
StateB
}
fn first(query: Query<&FirstComponent>)
{
for entity in query.iter()
{
println!("First: {:?}", entity)
}
}
fn first_no_second(query: Query<&FirstComponent, Without<SecondComponent>>)
{
for entity in query.iter()
{
println!("First without Second: {:?}", entity)
}
}
fn first_and_second(query: Query<&FirstComponent, With<SecondComponent>>)
{
for entity in query.iter()
{
println!("First with Second: {:?}", entity)
}
}
How bevy's ecs understands which systems need to be started for a certain Queue. Within World, the components are somehow related to the Entity, am I right? Is it possible to somehow trace this connection from the outside? I really like how it works, for me it looks like magic, but I would like to understand what is happening "under the hood"