Component features for resources#23168
Draft
Trashtalk217 wants to merge 3 commits intobevyengine:mainfrom
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Now that resources are components, any component feature can become a resource feature. We know we can, now we just need to figure out whether or not we should.
Solution
We're going through a list of features we can enable for resources, in the order of most reasonable to least reasonable. I invite everyone to add to this discussion and list reasons for or against adding a feature. This includes weird edge cases, confusing semantics, or novel use cases. In order to learn more about the features I'm referencing in a Component context, the documentation is a good start.
Configurable Storage
Pretty much a no-brainer: 0 downsides.
Custom Entity Mapping
I'd have to do some testing to see that this actually does work in the contexts of entity cloning and scenes, but this should also be a pretty clear win without any downside.
Clone Behaviour
Used in very similar contexts to custom entity mapping. I should write tests for this, but otherwise a pretty clear win.
Immutable Resources
Why would you want an immutable resource? Not sure, but from now, you can. The only downside is that methods operating on mutable resources need to be annotated with
Component<Mutability = Mutable>. Take for exampletry_resource_scope:So there's a bit of extra boilerplate there.
Resource Hooks
The original PR #20934 added support for observers. Component (resource) hooks, are slightly different. One potential problem with adding support for this is that
resource_hookmight read an invalid world state.The 'resource-ness' of
MyResourceis determined by two things: the presence of anIsResourcemarker component on the same entity and there being an entry in theResourceEntitieshashmap (stored onWorld).IsResourceis a required component and is added alongsideMyResourcein the same insertion.Afterwards, the
ResourceEntitieshashmap is updated in theon_inserthook forIsResource. I'm uncertain whether or not this runs before or after anyon_insert/on_addhooks forMyResource, so theMyResourcehooks might perceive an invalid world state. The same goes for theon_discard/on_removehooks.This might not be such a big problem, because hooks are intended to maintain invariants. Only after all hooks are ran, can a user expect that everything is in order, but not before. If this is documented correctly, I think we can allow this.
Required Components
Required components are really useful. Replicon uses them for networking components and it would be good to use the same code for resources. However there is a number of problems:
#[require(MyResource)]on a component or resource.#[require(IsResource)]? Doubly requiringIsResourceon a resource probably shouldn't be possible.Relations
I don't know what this would even mean in the context of resources.