Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First spawning after the startup set #3

Closed
EmiOnGit opened this issue Mar 19, 2023 · 4 comments
Closed

First spawning after the startup set #3

EmiOnGit opened this issue Mar 19, 2023 · 4 comments

Comments

@EmiOnGit
Copy link

EmiOnGit commented Mar 19, 2023

I think it is common to spawn some entities in startup systems and then assume that they get spawned before other systems are spawned.

Following example:

use bevy::prelude::*;
use spew::prelude::*;
#[derive(Debug, PartialEq, Eq)]
enum Objects {
    Player,
}
fn main() {
    App::new()
        .add_plugin(SpewPlugin::<Objects, ()>::default())
        .add_spawner((Objects::Player, spawn_player))
        .add_system(player_state)
        .add_startup_system(setup)
        .run();
}
#[derive(Component)]
struct PlayerMarker;
fn spawn_player(world: &mut World, _input: ()) {
      world.spawn(PlayerMarker);

}
fn setup(mut spawn_events: EventWriter<SpawnEvent<Objects, ()>>) {
      spawn_events.send(SpawnEvent {
            object: Objects::Player,
            data: (),
      });
}
fn player_state(player: Query<&PlayerLabel>) {
     let _player_label = player.single();
}

This would crash since the event would only be processed after the first frame
since the event will first be processed in the first frame and entity spawns are only processed in the last stage (I think) .

It would be nice to have some kind of new CoreSet which checks if any startup system send spawn events and already spawns them accordingly before the normal systems begin to run

@janhohenheim
Copy link
Owner

Hmm, I agree. I have no idea how I would implement that though :/

@janhohenheim
Copy link
Owner

Thanks for your feedback btw, I very much appreciate it :)

@janhohenheim
Copy link
Owner

Update: Figured it out, your example works now: https://github.com/janhohenheim/spew/blob/main/examples/query_after_spawn.rs 😄

@EmiOnGit
Copy link
Author

Wow, you completely smashed the issues I opened! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants