I spawn a sprite and attach a struct to it, then get its translation but the game crashes saying the entity doesn't exist.
pub fn setup_ingame(
mut commands: Commands,
asset_server: Res<AssetServer>,
ingame_setup: ResMut<InGameSetup>,
mut obstacles: ResMut<Obstacles>,
mut spawn_ground: ResMut<SpawnGround>,
mut ground_transform: Query<&mut Transform, With<Ground>>,
){
if ingame_setup.run {
if spawn_ground.run {
commands.spawn((SpriteBundle {
transform: Transform::from_xyz(0.0, -378.0, 0.0),
texture: asset_server.load("ground.png"),
..Default::default()
},
Ground,
))
.insert(RigidBody::KinematicVelocityBased);
let ground_pos = ground_transform.single_mut();
let mut x = ground_pos.translation.x;
spawn_ground.run = false;
}
}
}