MrGVSV/bevy_proto

Entity is empty when spawning from a SystemState

zwazel opened this issue · 1 comments

zwazel commented

I use bevy_mod_script to get Scripting working with my project.
I have a function that can be called by scripts, that takes the World and a String as a Parameter, goal of the function is to simply spawn a prototype.
As I only have access to the World, I somehow have to get ProtoCommands:

let mut system_state: SystemState<ProtoCommands> = SystemState::new(&mut world);

and with that I can then spawn a Prototype, so the whole system looks like this:

pub(crate) fn spawn_mod(world: &mut ScriptWorld, mod_name: ImmutableString) -> Dynamic {
    let mut world = world.write();

    let mut system_state: SystemState<ProtoCommands> = SystemState::new(&mut world);
    let mut proto_commands = system_state.get_mut(&mut world);
    let spawned_mod = proto_commands.spawn(mod_name.as_str()).id();

    Dynamic::from(spawned_mod)
}

It does spawn an entity, but it stays empty.
image

It's my first time working with SystemState, so maybe I misunderstand something.

zwazel commented

Ok, figured it out.
Fixed by manually calling system_state.apply(&mut world); in the function.