Skip to content
Discussion options

You must be logged in to vote

However, the direct EntityCommands extension trait isn't very flexible: now we need a different extension method for every place we want to use this pattern!

Instead, let's pass in a closure into our extension method, which controls which builder we're using.

This approach has an elaborate setup, but very flexible and quite comfortable to use. Critically, by setting your Config type to something more complex, we can pass in things like ResMut<Assets<Mesh>> or Handle<ColorMaterial>.

#[test]
fn entity_commands_closure_extension() {
    use bevy::ecs::system::{EntityCommands, RunSystemOnce};

    trait EntityCommandsExt<Config> {
        fn spawn_dynamic_bundle(
            &mut self,

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by alice-i-cecile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
A-ECS Entities, components, systems, and events
1 participant