Skip to content

Conversation

@maniwani
Copy link
Contributor

Objective

  • A more intuitive distinction between the two. remove_intersection is verbose and unclear.
  • EntityMut::remove and Commands::remove should match.

Solution

  • What the title says.

Migration Guide

Before

fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).remove::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove_intersection::<Parent>();
        }
    }
}

After

fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).take::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove::<Parent>();
        }
    }
}

@maniwani maniwani changed the title Rename remove_intersection to remove and remove to take EntityMut: rename remove_intersection to remove and remove to take Feb 24, 2023
@maniwani maniwani added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Feb 24, 2023
@maniwani maniwani requested a review from MrGVSV February 24, 2023 18:02
@maniwani
Copy link
Contributor Author

maniwani commented Feb 24, 2023

Just want to make sure I didn't choose the wrong method in bevy_reflect.

Comment on lines -102 to -105
///
/// # Panics
///
/// Panics if there is no [`Component`] of the given type.
Copy link
Member

Choose a reason for hiding this comment

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

So entity.remove::<T>() won't panic if the component doesn't exist on the entity? (Did it even panic before?)

Copy link
Contributor Author

@maniwani maniwani Feb 24, 2023

Choose a reason for hiding this comment

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

Hmm, I don't think remove ever panicked (well, ig if you call unwrap when it returns None).

But there's a subtle difference when T is a tuple/bundle.

remove (take) does not remove anything unless the entity has all the components in the bundle. remove_intersection (remove) will remove the ones it does have.

It wasn't clear to me which one bevy_reflect should use.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. Well ReflectComponent only operates on a single component anyways, so either should work fine 😄

@james7132 james7132 added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 24, 2023
@james7132
Copy link
Member

@maniwani mind fixing the CI failures? Will merge after that, though we may need to manually add the changes into the 0.10 migration guide.

@james7132 james7132 added this to the 0.10 milestone Feb 25, 2023
@james7132
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Feb 25, 2023
… `take` (#7810)

# Objective

- A more intuitive distinction between the two. `remove_intersection` is verbose and unclear.
- `EntityMut::remove` and `Commands::remove` should match.


## Solution

- What the title says.

---

## Migration Guide

Before
```rust
fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).remove::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove_intersection::<Parent>();
        }
    }
}
```

After
```rust
fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).take::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove::<Parent>();
        }
    }
}
```
@bors
Copy link
Contributor

bors bot commented Feb 25, 2023

Build failed:

  • run-examples

@mockersf
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Feb 26, 2023
… `take` (#7810)

# Objective

- A more intuitive distinction between the two. `remove_intersection` is verbose and unclear.
- `EntityMut::remove` and `Commands::remove` should match.


## Solution

- What the title says.

---

## Migration Guide

Before
```rust
fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).remove::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove_intersection::<Parent>();
        }
    }
}
```

After
```rust
fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).take::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove::<Parent>();
        }
    }
}
```
@bors bors bot changed the title EntityMut: rename remove_intersection to remove and remove to take [Merged by Bors] - EntityMut: rename remove_intersection to remove and remove to take Feb 26, 2023
@bors bors bot closed this Feb 26, 2023
@maniwani maniwani deleted the remove_and_take branch February 28, 2023 04:16
ProfLander pushed a commit to shfty-rust/bevy that referenced this pull request Mar 19, 2023
… `take` (bevyengine#7810)

# Objective

- A more intuitive distinction between the two. `remove_intersection` is verbose and unclear.
- `EntityMut::remove` and `Commands::remove` should match.


## Solution

- What the title says.

---

## Migration Guide

Before
```rust
fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).remove::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove_intersection::<Parent>();
        }
    }
}
```

After
```rust
fn clear_children(parent: Entity, world: &mut World) {
    if let Some(children) = world.entity_mut(parent).take::<Children>() {
        for &child in &children.0 {
            world.entity_mut(child).remove::<Parent>();
        }
    }
}
```
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 M-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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants