Skip to content

Hybrid Resources#24597

Draft
Trashtalk217 wants to merge 1 commit into
bevyengine:mainfrom
Trashtalk217:hybrid-resources
Draft

Hybrid Resources#24597
Trashtalk217 wants to merge 1 commit into
bevyengine:mainfrom
Trashtalk217:hybrid-resources

Conversation

@Trashtalk217

Copy link
Copy Markdown
Contributor

Objective

This is a response to #24591 and #24592.

In short, during the resources-as-components proces it was decided that trait Resource : Component instead of using a wrapper component like ResourceData<R: Resource>(R). This caused one major regression:

#[derive(Component, Resource)] // error -> can't derive Component twice!
struct Foo;

Double derives were no longer possible. This is occasionally useful. One particular example would be global settings with local overrides. You would set a global default which you could locally override for a specific entity - all within the same type. Because this was now disallowed, you had to split your struct into two:

#[derive(Component)]
struct LocalFoo;

#[derive(Resource)]
struct GlobalFoo;

This is verbose and generally not ideal.

Solution

Introduce HybridResource: Types that implement this trait function both as a Resource and a Component, roughly mimicking the old #[derive(Resource, Component)] behaviour.

Problems

  • I drew this up rather quickly, so this is only a draft. It's more meant as a proof of concept. The name is bikesheddable.
  • The hooks I currently have can very easily be cleaned up with components-as-entities
  • Currently the hooks can't make a distinction between world.spawn() and world.insert_resource() so if you do world.spawn() before doing world.insert_resource() it will assume that the world.spawn()ed value is the resource, not the component. A real solution might just have to bring back the wrapper type.

@Trashtalk217 Trashtalk217 added the A-ECS Entities, components, systems, and events label Jun 12, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

1 participant