Comments (5)
Ah yes, I have used this pattern myself, I just never thought of describing it as "entities as events" :D.
Spawn an entity to trigger something to be done, carrying the relevant data in components. Have a system watch for such entities and do the things.
Thanks for the detailed breakdown of advantages/disadvantages. This is very useful information.
from bevy-cheatbook.
- Without some convenience wrappers, creating entities just for events can quickly get boilerplate-y, along with destroying them afterwards. This isn't so bad to fix with a number of helpers to produce and consume these special entities.
Very much agree. I'm curious if there are abstractions worth pulling out into a storage system.
- Archetype fragmentation. Wouldn't this lead to a number of heterogeneous archetypes of which only a small number exist at a time? I'm not deeply familiar with the per-archetype overhead in bevy.
This is massively improved in Bevy if you opt into sparse set storage for most of your components used in this pattern, introduced in ECS v2 :) In my original use case (a TTRPG-like turn-based game), expressivity and development speed are much much more important than performance, so I probably won't bother toggling this behavior until the game releases.
- The big one: debugging. Indirect message passing systems are a major pain to debug since you lose stack trace information as soon as the event is queued (or in this case, created and put into the world).
I definitely share your concerns here. I'm hopeful that we can get better tools for this in Bevy itself; the ability to reconstruct what's changed an entity / component is invaluable. Sliced (per component) diagrams of system organization would also be very useful.
from bevy-cheatbook.
This is a reasonable pattern for an ECS and could be nice as a backing layer for a system built on top of it for convenience. It may be worth looking at how other systems do events, such as EnTT's approach (which I believe is a more traditional C++ signal system). I have a few concerns:
-
Without some convenience wrappers, creating entities just for events can quickly get boilerplate-y, along with destroying them afterwards. This isn't so bad to fix with a number of helpers to produce and consume these special entities.
-
Archetype fragmentation. Wouldn't this lead to a number of heterogeneous archetypes of which only a small number exist at a time? I'm not deeply familiar with the per-archetype overhead in bevy.
-
The big one: debugging. Indirect message passing systems are a major pain to debug since you lose stack trace information as soon as the event is queued (or in this case, created and put into the world). If this approach is to become the norm, I recommend working out a way to trace the origins of events in a debug context to see where an offending event came from. In the past I've tacked this (expensively) by storing the complete stack trace at the moment the event was created, as a string, in the event itself. This might be a little tricky in a bevy context, but having that information is a debugging lifesaver.
from bevy-cheatbook.
Following up on the command processing delays listed in my first post, this issue is the place to follow for possible improvements :) This would improve this pattern's ergonomics dramatically.
from bevy-cheatbook.
@recatek Actually entt's author (@skypjack) advised me before for using entities as events. I am at the moment trying to leverage that. I really like the approach and this is one of the major reasons I chose entt because it is very well suited for this use case (Sparseset and it is designed as a generic flexible container rather than an esc system only), adding/removing components will be very fast. I like to think of this approach to be like TCP way of encapsulating packets adding more and more data to it as it goes through the link. IMHO it is more suited for high volume of events than signals, it will lead to less lookups.
from bevy-cheatbook.
Related Issues (20)
- How to support dynamic linking on Windows HOT 1
- Windows debugging error
- Small code typo on touch input page HOT 1
- Updated State system (Bevy 0.12)
- Inconstant / non-working code example HOT 1
- Proposal to Enhance Bevy Learning Resources and Collaboration: Please update to Bevy .12 and merge it to the parent project. HOT 1
- Add explanation for how to setup a 2d camera in the "2d camera setup" part of the book HOT 2
- 404 on example: cursor2world
- VS Code debugger on Windows
- compex
- Consider advising users not to use Trunk for wasm builds, or warn them about some caveats
- Cross-compile: Linux -> Win, Bevy 0.12 build fails on Blake 1.5 - solution.
- Broken link in chapter 14.4. The App
- Dev Tools and Editors page incorrectly marked as outdated HOT 1
- 3D Pan+Orbit Camera example in cookbook does not work with 0.12
- Broken link in the Resources section of the List of Bevy Builtins page
- AppState getting HOT 1
- Add description of how to deploy to web with WebGPU on the wasm page.
- Plugins guidelines link HOT 1
- Update `DefaultPlugins` documentation link HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bevy-cheatbook.