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

Change ReflectMapEntities to operate on components before insertion #15422

Merged
merged 5 commits into from
Oct 1, 2024

Conversation

jrobsonchase
Copy link
Contributor

@jrobsonchase jrobsonchase commented Sep 25, 2024

Previous PR #14549 was closed in error and couldn't be reopened since I had updated the branch 😿

Objective

Fixes #14465

Solution

ReflectMapEntities now works similarly to MapEntities in that it works on the reflected value itself rather than the component in the world after insertion. This makes it so that observers see the remapped entities on insertion rather than the entity IDs from the scene.

ReflectMapEntities now works for both components and resources, so we only need the one.

Testing

  • New unit test for Observers + DynamicScenes
  • New unit test for Observers + Scenes
  • Open to suggestions for other tests!

Migration Guide

  • Consumers of ReflectMapEntities will need to call map_entities on values prior to inserting them into the world.
  • Implementors of MapEntities will need to remove the mappings method, which is no longer needed for ReflectMapEntities and has been removed from the trait.

@jrobsonchase jrobsonchase marked this pull request as ready for review September 25, 2024 10:59
@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 A-Scenes Serialized ECS data stored on the disk X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward A-Networking Sending data between clients, servers and machines labels Sep 26, 2024
@jrobsonchase
Copy link
Contributor Author

I've rebased this on #15425 since it's gaining traction and I like its approach way better than what I had here previously.

@jrobsonchase jrobsonchase force-pushed the pre_map_entities branch 7 times, most recently from 51198ef to 55767d1 Compare September 28, 2024 17:17
@jrobsonchase
Copy link
Contributor Author

Welp, this has now been un-rebased on #15425 after realizing the approach there wouldn't work for HashSets. So now we're back to the original plan.

@jrobsonchase
Copy link
Contributor Author

@alice-i-cecile This is ready for review once more!

@jrobsonchase jrobsonchase force-pushed the pre_map_entities branch 2 times, most recently from 148b667 to fe173a1 Compare September 29, 2024 01:26
This makes EntityMapper object-safe and obviates the need for the `Dyn` variant.
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Oct 1, 2024
@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Oct 1, 2024
Copy link
Contributor

@Shatur Shatur 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!
Left a small suggestion.

crates/bevy_ecs/src/reflect/map_entities.rs Outdated Show resolved Hide resolved
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
@alice-i-cecile alice-i-cecile requested a review from Shatur October 1, 2024 17:18
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 1, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 1, 2024
Merged via the queue into bevyengine:main with commit 40e88dc Oct 1, 2024
27 checks passed
robtfm pushed a commit to robtfm/bevy that referenced this pull request Oct 4, 2024
…evyengine#15422)

Previous PR bevyengine#14549 was closed in
error and couldn't be reopened since I had updated the branch
:crying_cat_face:

# Objective

Fixes bevyengine#14465

## Solution

`ReflectMapEntities` now works similarly to `MapEntities` in that it
works on the reflected value itself rather than the component in the
world after insertion. This makes it so that observers see the remapped
entities on insertion rather than the entity IDs from the scene.

`ReflectMapEntities` now works for both components and resources, so we
only need the one.

## Testing

* New unit test for `Observer`s + `DynamicScene`s
* New unit test for `Observer`s + `Scene`s
* Open to suggestions for other tests!

---

## Migration Guide

- Consumers of `ReflectMapEntities` will need to call `map_entities` on
values prior to inserting them into the world.
- Implementors of `MapEntities` will need to remove the `mappings`
method, which is no longer needed for `ReflectMapEntities` and has been
removed from the trait.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
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 A-Networking Sending data between clients, servers and machines A-Scenes Serialized ECS data stored on the disk C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Observers and hooks doesn't pair well with mapped entities
3 participants