big_space
big_space copied to clipboard
How to access GridCommands via a Query?
Amazing crate, thank you. I'm struggling to figure out: after I spawned a new grid and some children in it, how do you come back to that grid and add more entities to it? Grid is a component and it can be queried for:
fn setup1(
mut commands: Commands,
) {
commands.spawn_big_space_default(|root_grid| {
root_grid.insert(RootGrid);
// add stuff to root_grid ...
}
}
// ...
fn setup2(
mut root_grid: Query<&mut Grid<GP>, With<RootGrid>>,
) {
let mut root_grid = root_grid.single_mut();
// ERROR: `root_grid` is not a `GridCommands`, so `spawn_spatial()` is not found for it
root_grid.spawn_spatial((...));
}
I guess my question applies to any grid, not just the root one. Please help?
Took me a while to find a manual workaround that the BigSpace's validator asks not to use 😉:
fn setup2(
mut commands: Commands,
root_grid: Query<(Entity, &Grid<GP>), With<RootGrid>>,
) {
let (root_grid_id, root_grid) = root_grid.single();
let object_pos = DVec3::new(/* position*/);
let (object_cell, object_pos) = root_grid.translation_to_grid(object_pos);
commands
.spawn((
object_cell,
Transform::from_translation(object_pos),
))
.set_parent(root_grid_id);
}
The short answer is that this isn't implemented yet. Getting access to those commands is on my todo list!
resolved in #52