Skip to content

Immutable Resources fix#24424

Open
Trashtalk217 wants to merge 5 commits into
bevyengine:mainfrom
Trashtalk217:immutable-resources-fix
Open

Immutable Resources fix#24424
Trashtalk217 wants to merge 5 commits into
bevyengine:mainfrom
Trashtalk217:immutable-resources-fix

Conversation

@Trashtalk217
Copy link
Copy Markdown
Contributor

Objective

Fixes #24285.

Solution

Add UnsafeWorldCell::get_resource_assume_mutable, World::modify_resource and World::modify_resource_by_id and updated the migration guide.

Testing

The new methods are essentially identical to their component counterparts.

@Trashtalk217 Trashtalk217 added the A-ECS Entities, components, systems, and events label May 24, 2026
@Trashtalk217 Trashtalk217 added this to the 0.19 milestone May 24, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in ECS May 24, 2026
@Trashtalk217
Copy link
Copy Markdown
Contributor Author

I don't know where all the migration guides have gone to, but for future reference: I'd like to add the following to the resources_as_components migration guide:

If it's not possible to add the bound, use either `UnsafeWorldCell::get_resource_mut_assume_mutable`, `UnsafeWorldCell::get_resource_by_id` and make sure that the safety conditions are satisfied. 
There's also `World::modify_resource` and `World::modify_resource_by_id`, that behave exactly like their component counterparts.
Lastly, it's also possible to use the `*_assume_mutable` component methods for this purpose, but you'd first have to retrieve the resource entity from `ResourceEntities`.

And also the PR number on the top.

@kfc35
Copy link
Copy Markdown
Contributor

kfc35 commented May 24, 2026

The migration guides are in the release-0.19.0 branch https://github.com/bevyengine/bevy/tree/release-0.19.0/_release-content/migration-guides

I would keep this PR separate for logic fixes that should also be in main and then to open a separate one to update the migration guide specifically on the release branch

@urben1680
Copy link
Copy Markdown
Contributor

urben1680 commented May 24, 2026

Is there a reason you did not add World::get_resource_assume_mutable(_by_id) like they exist for components at EntityWorldMut (1, 2)?

EDIT: ah you suggest to first retrieve the entity in the migration guide. Dunno if it would hurt much to just offer a resource method.

@kfc35 kfc35 added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label May 25, 2026
Copy link
Copy Markdown
Contributor

@chescock chescock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, having versions of these APIs for resources seems important!

/// - no other references to the resource exist at the same time
/// - the resource `R` is mutable
#[inline]
pub unsafe fn get_resource_mut_assume_mutable<R: Resource>(self) -> Option<Mut<'w, R>> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change get_resource_mut to delegate to this, like how UnsafeEntityCell::get_mut just calls get_mut_assume_mutable?

Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me! i agree that get_resource_mut should delegate to the new method

@kfc35 kfc35 added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged D-Straightforward Simple bug fixes and API improvements, docs, test and examples and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 27, 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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Immutable resources need a migration guide

4 participants