Systems as entities #16618
Labels
A-ECS
Entities, components, systems, and events
C-Feature
A new feature, making something new possible
D-Complex
Quite challenging from either a design or technical perspective. Ask for help!
S-Needs-Design
This issue requires design work to think about how it would best be accomplished
Background
Today,
bevy_ecs
can roughly be split into two parts:World
, entities, components, resources, archetypes and querying.The data storage part is very flexible and powerful. It has facilities for storing arbitrary data on objects, composing data on objects, reacting to changes in data, and so on.
On the other hand, schedules are a hand crafted storage solution for systems which includes all manner of metadata: system name, before/after relations, system sets it belongs to, etc.
As a result, we have to build a lot of APIs. Schedules today can't have systems be removed (#279, wow that's an old issue). We'd have to come up with an ID scheme for systems, provide a function to remove systems, and also make sure the schedule graph reacts appropriately to the change.
Proposal: Systems-as-entities
(queue anything-as-entities meme)
Instead of building more stuff on top of the system storage, we can instead rewrite it to use the data storage and access part! Now we don't need an ID scheme for systems: it's just an
Entity
. Now we don't need a function to remove systems: that's just despawning an entity. As for having the schedule graphs react to changes, we have several tools to handle this. Change detection, hooks, and observers could be used.As part of this, we will likely want schedules and system sets to also be entities. Systems can then have a system set or schedule component that matches the particular type.
Issues that help this effort
Immutable Components (#16372)
Today, we likely need to use change detection to keep things in sync. With immutable components, we can just use hooks to sync any schedule data structures.
🌈 Relations (#3742)
Today, we either need to store before/after relationships as one component for all a system's constraints, or we need to spawn an entity to represent that constraint. Either way, these are both cumbersome to manage. With relations, we can use them to represent all the before/after constraints as relations. Finding all edges is very easy then.
Similarly, schedules and system sets could use relations to define which systems are in the schedule or system set.
Risks
Prior Art
flecs
implements systems as entities! Some of the cool features that just pop out for free was disabling systems the same way entities can be disabled!The text was updated successfully, but these errors were encountered: