#[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.