pub fn force_spawn_children() -> SystemConfigs👎Deprecated since 0.2.4: see documentation at https://github.com/Zeenobit/moonshine_spawn for details
Expand description
Returns a SystemConfigs which immediately spawns all pending SpawnChildren requests.
§Usage
Typically, the spawn system spawns children automatically during First schedule.
In some cases, however, it may be necessary to forcibly spawn children due to ordering issues.
§Example
use bevy::prelude::*;
use moonshine_spawn::{prelude::*, force_spawn_children};
#[derive(Component)]
struct Bar;
#[derive(Bundle)]
struct Foo {
children: SpawnChildren,
}
impl Foo {
fn new() -> Self {
Self {
children: spawn_children(|parent| {
parent.spawn(Bar);
})
}
}
}
fn setup(mut commands: Commands) {
commands.spawn(Foo::new());
}
fn post_setup(bar: Query<&Bar>) {
let _ = bar.single();
// ...
}
App::new()
.add_plugins((MinimalPlugins, SpawnPlugin))
// Without `force_spawn_children()`, `post_setup` would panic!
.add_systems(Startup, (setup, force_spawn_children(), post_setup).chain())
.update();