#Call systems via other systems

1 messages · Page 1 of 1 (latest)

bitter cradle
#
#[derive(Component)]
#[require(Transform, Mesh3d, MeshMaterial3d<StandardMaterial>)]
pub struct Block {
    pub display_name: String,
}

...

pub fn spawn_blocks(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {

// ...
// inside some for loops
commands.spawn((
                Block {
                    display_name: format!("Block {}", row * col),
                },
                Transform::from_xyz(x, 0.0, z),
                Mesh3d(meshes.add(cube)),
                MeshMaterial3d(material.clone()),
            ));
}

Although i do add #[require(...)] to the Block struct, these components like Transform and Mesh3D aren't really required at creation (since omitting them just uses their default). Is there a way to guarantee that block Mesh3D component will ALWAYS be a Cuboid? Is there a way I can have both a spawn_block and a spawn_blocks function where one takes the commands, assert_server, meshes, ect and the other takes only the handles and the commands? Should I be using messages instead?

I will always spawn blocks during startup but I also will do it programmatically.

bitter cradle
#

Call systems via other systems

icy viper
#

I think you can give require any function pointer returning the type

#

But in Mesh3d case it's more complicated bc you need to get the asset handle

#

Youll probably want to use hooks "on_insert" and make the component immutable

eternal dove
#

I asked a similar question a while back, the current answers are essentially "use an observer and event" I.e. a SpawnBlock event which both systems commands.trigger, or use a custom command if you have extreme performance needs or would rather work with &mut World instead of SystemParams.

In the future the answer will be "Use bsn", but we're not quiiiite there yet.