Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn entities with an EntityCommand-based abstraction #223

Open
benfrankel opened this issue Aug 4, 2024 · 3 comments
Open

Spawn entities with an EntityCommand-based abstraction #223

benfrankel opened this issue Aug 4, 2024 · 3 comments
Assignees
Labels
blocked Requires work upstream enhancement New feature or request
Milestone

Comments

@benfrankel
Copy link
Collaborator

benfrankel commented Aug 4, 2024

An example of how the proposed API looks in practice: https://github.com/benfrankel/bevy_jam_template/blob/main/src/screen/title.rs.

Benefits:

  • You get an EntityCommands back immediately.
  • You can access SystemParams ergonomically by adding them as arguments.
  • You can pass in extra data (e.g. struct Projectile { lifetime, .. }).
  • Converting a "pure" entity spawning system to one that takes in extra data is relatively easy:
    • Define your data type, like struct Projectile.
    • Implement EntityCommand for Projectile, and delegate to the spawning system with world.run_system_once_with((id, self), projectile).
    • Change In(id): In<Entity> to In((id, this)): In<(Entity, Projectile)>.

Drawbacks:

  • Requires extension traits.
  • Unfamiliar approach (using observers to spawn things is unfamiliar as well).
  • spawn_fn and spawn_with unfortunately couldn't be merged into one method.
  • A few lines of boilerplate to take in data. This could use a VS Code snippet to make it easier.
@benfrankel benfrankel added the enhancement New feature or request label Aug 4, 2024
@benfrankel benfrankel added this to the Bevy Jam 6 milestone Aug 4, 2024
@janhohenheim
Copy link
Member

I'm in favor.
Note that we went through many designs and this seems the cleanest by far imo. Bevy does not have the required answer to "How do I spawn an object composed of lots of stuff?" yet while still returning an EntityCommands, so we need to introduce an abstraction here.

@benfrankel benfrankel mentioned this issue Aug 4, 2024
15 tasks
@alice-i-cecile
Copy link
Member

I'm also in favour of this.

@janhohenheim
Copy link
Member

Blocked on upstreaming bevyengine/bevy#14278 and maybe bevyengine/bevy#14231

@janhohenheim janhohenheim added blocked Requires work upstream and removed ready for implementation The problem was discussed and is ready for a PR labels Aug 7, 2024
@benfrankel benfrankel changed the title Replace observers for spawning entities with an EntityCommand-based abstraction Spawn entities with an EntityCommand-based abstraction Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Requires work upstream enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants