bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
34.83k stars 3.4k forks source link

Observers as part of bundle #14204

Open MiniaczQ opened 1 month ago

MiniaczQ commented 1 month ago

What problem does this solve or what need does it fill?

Ability to add observers as part of a bundle would help a lot in composing entities.

What solution would you like?

The simplest way I can think of is to allow EntityCommand trait as part of bundles.

What alternative(s) have you considered?

Nothing else came to mind.

Additional context

Idea from https://discord.com/channels/691052431525675048/691052431974465548/1259529220892131348

alice-i-cecile commented 1 month ago

Aren't these just components? What else needs to be done?

MiniaczQ commented 1 month ago

Observers are components on a separate entity

So if I want to make a generic NPC bundle that has a "start conversation observer", I'd need to make an EntityCommands extension rather than a Bundle

alice-i-cecile commented 1 month ago

I think you can also stick an observer on the entity it's watching, which is fitting for this use case.

MiniaczQ commented 1 month ago

I see, I'd still like to hear James' opinion

@james-j-obrien what do you think?

james-j-obrien commented 1 month ago

While you can technically make the entity itself an observer you can't do that multiple times as the ObserverState component would get overridden leading to serious issues. If that was exposed in bundles users could easily accidentally break things by inserting different bundles that each have observers.

Alternatively we could introduce some other component that has an on_add hook to spawn an observer.

MiniaczQ commented 1 month ago

Installer (as I like to call it) pattern would work for simpler cases, good idea 🙂

Going one step further, how would observers work with serde/scenes? Was it discussed somewhere?