Resource hooks & immutable resources#24164
Conversation
|
It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note. Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes. |
|
Drop this pr in the resources as entities release notes please! |
alice-i-cecile
left a comment
There was a problem hiding this comment.
Needs a test please <3
There was a problem hiding this comment.
You should go through every API that offers mutable references to resources and add a <Mutability = Mutable> bound to them, I think that is missing. Like World::get_resource_mut. Untyped methods like World::get_resource_mut_by_id should fail if the resource is immutable.
Trashtalk217
left a comment
There was a problem hiding this comment.
ResMut shouldn't work on immutable resources. Is that implemented?
| /// or a function call that returns a function that can be turned into | ||
| /// a `ComponentHook`, e.g. `get_closure("Hi!")`. | ||
| /// `function` can be elided if the path is `Self::on_add`, `Self::on_insert` etc. | ||
| #[proc_macro_derive(Resource, attributes(component))] |
There was a problem hiding this comment.
When I originally envisioned this, I called it #[resource(...)]. It doesn't really matter, but it might be easier to understand.
There was a problem hiding this comment.
I do not have a strong opinion on this, happy to change it.
|
This looks good now; is there anything else you'd like to do beyond getting CI passing? |
|
Please don't forget to address my note: #24164 (review) If you can mutate immutable resources via |
The dynamic methods refuse to return a
|
Seems not to be true, or you miss that I talk about
|
One disadvantage of allowing |
|
We could do both even. No strong feelings here, but I would like to get this merged in a timely fashion. |
There was a problem hiding this comment.
I think there are a handful of APIs that need <Mutability = Mutable> bounds:
ParamBuilder::resource_mutTemplateContext::resource_mutWorld::get_resource_or_initWorld::get_resource_or_insert_with
I wonder if try_resource_scope does need to do extra care for immutable resources to ensure that the insert and change tick are equal.
I'm not sure what you mean?
Thanks!
Resource scope doesn't care much about component mutability. But on main, the resource scope always set both added and changed to the value that changed had beforehand, making both wrong. Since I've had to touch that function anyways, I fixed it and added a test.
Note that a difference between But I've added a commit that switches |
Objective
Enables the resource derive macro to specify the attributes for
Also fixes
resource_scopeoverwriting change ticks and a few related doc comments.Showcase