Open
Description
This issue does not exist to argue the merits of Resources as Components, for some of the rationale we refer to this HackMD (this really should've been an RFC, huh?). This issue exists to track the progress on implementation and to reference in code when it is only partially working. If there are steps you feel like should be added, or if there are problems with this approach, please let me know.
Implementation Plan
This is a tracking issue for the Resources as Components. This outline is roughly copied from #17485.
- Define marker components
IsResource
andResourceEntity
and spawn them alongside resources. (in progress: Add entities alongside resources #19711) - Add a cache that links Resources to their respective entities (in progress: Add entities alongside resources #19711)
- Change the APIs of
world.iter_entities()
,world.clear_entities()
and assorted other methods to ignore resource entities. - Make Resource a Component, and change the derive macro to derive a Component also. Also store the actual resource data on the resource entities. Note that at this point, the usual resource infrastructure exists alongside the entities, which are spawned and respawned alongside Resources.
- Remove or shrink ReflectResource
- Make sure the caller information can be passed into entity spawning.
- Move resource access over from the old storage to the entities. Think
Query<Res<Example>>
,world.iter_resources()
, and so on. - Remove all of the resource internals (before this, they're marked with expect(dead_code)).
I'm guessing that I could split out several of these items into smaller things, but this suffices as a rough outline for now.