-
-
Couldn't load subscription status.
- Fork 4.2k
Store Resources as components on singleton entities #20934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Store Resources as components on singleton entities #20934
Conversation
… into resource_entity_lookup
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
This is part of #19731.
Resources as Components
Motivation
More things should be entities. This simplifies the API, the lower-level implementation and the tools we have for entities and components can be used for other things in the engine. In particular, for resources, it is really handy to have observers, which we currently don't have. See #20821 under 1A, for a more specific use.
Current Work
This removes the
resourcesfield from the world storage and instead store the resources on singleton entities. For easy lookup, we add aHashMap<ComponentId, Entity>toWorld, in order to quickly find the singleton entity where the resource is stored.Because we store resources on entities, we derive
ComponentalongsideResource, this means thatturns into
This was also done for reflections, meaning that
becomes
In order to distinguish resource entities, they are tagged with the
IsResourcecomponent. Additionally, to ensure that they aren't queried by accident, they are also tagged as being internal entities, which means that they don't show up in queries by default.Drawbacks
Resourceand aComponent, becauseResourceexpands to also implementComponent, this means that this throws a compiler error as it's implemented twice.ReflectComponentyou need to importbevy_ecs::reflect::ReflectComponentevery time you use#[reflect(Resource)]. This is kind of unintuitive.Future Work
Accessin the ECS, to only deal with components (and not components and resources).Res<Resource>toSingle<Ref<Resource>>(or something similair).ReflectResource.