Skip to content
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

Updated World, UnsafeWorldCell Resource methods to use Res, ResMut #9940

Closed

Conversation

bushrat011899
Copy link
Contributor

Objective

Solution

  • Updated UnsafeWorldCell Resource methods to return either Res or ResMut where appropriate, using get_resource_with_ticks to obtain the relevant data.
  • Updated associated methods in World
  • Cascaded changes across Bevy as required.

Changelog

  • Updated UnsafeWorldCell::get_resource(_mut) to return Res/ResMut
  • Updated World::(get_)resource(_mut) to return Res/ResMut
  • Updated World::resource_scope to use ResMut

Migration Guide

Simply use into_inner() to retrieve the inner reference for &R being replaced with Res, and into for Mut and ResMut.

@JoJoJet
Copy link
Member

JoJoJet commented Sep 29, 2023

I don't see much reason to change Mut<> to ResMut<>. They do the same thing -- the only reason that ResMut exists is because with SystemParam, you have to distinguish between components and resources via the type itself. Here, we're able to use the method's name to distinguish between components and resources, making ResMut unnecessary. We already treat Mut as the "canonical" change detection smart pointer: ResMut::reborrow returns Mut, for example.

@bushrat011899
Copy link
Contributor Author

the only reason that ResMut exists is because with SystemParam [...] We already treat Mut as the "canonical" change detection smart pointer: ResMut::reborrow returns Mut, for example.

Between that, and this comment from @cart, I'm going to switch this PR to draft and make some fairly major changes.

@bushrat011899 bushrat011899 marked this pull request as draft September 29, 2023 03:57
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR labels Sep 29, 2023
github-merge-queue bot pushed a commit that referenced this pull request Jan 28, 2024
…ref` (#11561)

# Objective

It's sometimes desirable to get a `Res<T>` rather than `&T` from
`World::get_resource`.
Alternative to #9940, partly adresses #9926

## Solution

added additional methods to `World` and `UnsafeWorldCell` to retrieve a
resource wrapped in a `Res`.
- `UnsafeWorldCell::get_resource_ref`
- `World::get_resource_ref`
- `World::resource_ref`

I can change it so `World::resource_mut` returns `ResMut` instead of
`Mut` as well if that's desired, but that could also be added later in a
seperate pr.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Mike <mike.hsu@gmail.com>
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
tjamaan pushed a commit to tjamaan/bevy that referenced this pull request Feb 6, 2024
…ref` (bevyengine#11561)

# Objective

It's sometimes desirable to get a `Res<T>` rather than `&T` from
`World::get_resource`.
Alternative to bevyengine#9940, partly adresses bevyengine#9926

## Solution

added additional methods to `World` and `UnsafeWorldCell` to retrieve a
resource wrapped in a `Res`.
- `UnsafeWorldCell::get_resource_ref`
- `World::get_resource_ref`
- `World::resource_ref`

I can change it so `World::resource_mut` returns `ResMut` instead of
`Mut` as well if that's desired, but that could also be added later in a
seperate pr.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Mike <mike.hsu@gmail.com>
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
@JoJoJet
Copy link
Member

JoJoJet commented Feb 12, 2024

Going to close this out since we're likely going to move in the direction described in #11825

@JoJoJet JoJoJet closed this Feb 12, 2024
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 C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

World::resource and allies do not return Res / ResMut smart pointers
3 participants