Skip to content

Conversation

@Ceedrich
Copy link

@Ceedrich Ceedrich commented Oct 23, 2025

Objective

When working with complex spawn hierarchies, it can sometimes be useful to spawn multiple for each object in a list. I encountered this, when using bevy_enhanced_input. Consider the following scenario:

struct KeyboardConfig {
  up: [Binding; 3],
  down: [Binding; 3],
  left: [Binding; 3],
  right: [Binding; 3],
}

//Without FlatSpawnVec
impl KeyboardConfig {
  fn x_axis(&self) -> impl SpawnableList<BindingOf> {
    SpawnIter(
      Spawn((self.left.0, Negate::all())),
      Spawn(self.right.0),
      Spawn((self.left.1, Negate::all())),
      Spawn(self.right.1),
      Spawn((self.left.2, Negate::all())),
      Spawn(self.right.2),
    ) 
  }
}


// With FlatSpawnVec
impl KeyboardConfig {
  fn x_axis(&self) -> impl SpawnableList<BindingOf> {
    FlatSpawnVec(self.left.into_iter().zip(self.right)
      .map(|(l, r)| (Spawn((l, Negate::all()), Spawn(r))
      .collect()
    ) 
  }
}

If the bindings didn't have a known size, this would not be possible without a FlatSpawnVec.

Solution

This can be solved by using a FlatSpawnVec implementation that spawns multiple entities per iteration. I could also see the vector being changed in favor of an iterator or similar.

Testing

I added a test bevy_ecs::spawn::test::flat_spawn_vec

@github-actions
Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

Copy link
Contributor

@hukasu hukasu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, not convinced

@hukasu hukasu added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events M-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 26, 2025
@github-actions
Copy link
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@github-actions
Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-21637

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible M-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants