Skip to content

Conversation

tim-blackbird
Copy link
Contributor

@tim-blackbird tim-blackbird commented Oct 6, 2022

I found myself doing

let child = commands.spawn(..).id();
commands.entity(parent).add_child(child);

When that could just be

commands.spawn(..).set_parent(parent);

Adding set_parent was trivial as it's just an AddChild command. Most of the changes are for remove_parent.
Also updated some outdated docs.

@alice-i-cecile alice-i-cecile added A-Hierarchy C-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Oct 7, 2022
@alice-i-cecile alice-i-cecile added this to the Bevy 0.9 milestone Oct 7, 2022
@BorisBoutillier
Copy link
Contributor

What is the value of creating a new RemoveParent instead of using the existing RemoveChidren for remove_parent ?
Same way that you have reused the AddChild for set_parent.

@tim-blackbird
Copy link
Contributor Author

RemoveParent does not require knowing the parent entity.

Your comment made me realize that RemoveChildren breaks the hierarchy if you give it a child that belongs to a different parent.
Going to PR a fix for that :v

@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 Oct 19, 2022
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Oct 24, 2022
I found myself doing
```rust
let child = commands.spawn(..).id();
commands.entity(parent).add_child(child);
```
When that could just be
```rust
commands.spawn(..).set_parent(parent);
```

Adding `set_parent` was trivial as it's just an `AddChild` command. Most of the changes are for `remove_parent`.
Also updated some outdated docs.

Co-authored-by: devil-ira <[email protected]>
@bors
Copy link
Contributor

bors bot commented Oct 24, 2022

Build failed (retrying...):

bors bot pushed a commit that referenced this pull request Oct 24, 2022
I found myself doing
```rust
let child = commands.spawn(..).id();
commands.entity(parent).add_child(child);
```
When that could just be
```rust
commands.spawn(..).set_parent(parent);
```

Adding `set_parent` was trivial as it's just an `AddChild` command. Most of the changes are for `remove_parent`.
Also updated some outdated docs.

Co-authored-by: devil-ira <[email protected]>
@bors bors bot changed the title Add set_parent and remove_parent to EntityCommands [Merged by Bors] - Add set_parent and remove_parent to EntityCommands Oct 24, 2022
@bors bors bot closed this Oct 24, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
…6189)

I found myself doing
```rust
let child = commands.spawn(..).id();
commands.entity(parent).add_child(child);
```
When that could just be
```rust
commands.spawn(..).set_parent(parent);
```

Adding `set_parent` was trivial as it's just an `AddChild` command. Most of the changes are for `remove_parent`.
Also updated some outdated docs.

Co-authored-by: devil-ira <[email protected]>
@tim-blackbird tim-blackbird deleted the set_parent branch November 6, 2022 18:24
Pietrek14 pushed a commit to Pietrek14/bevy that referenced this pull request Dec 17, 2022
…6189)

I found myself doing
```rust
let child = commands.spawn(..).id();
commands.entity(parent).add_child(child);
```
When that could just be
```rust
commands.spawn(..).set_parent(parent);
```

Adding `set_parent` was trivial as it's just an `AddChild` command. Most of the changes are for `remove_parent`.
Also updated some outdated docs.

Co-authored-by: devil-ira <[email protected]>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…6189)

I found myself doing
```rust
let child = commands.spawn(..).id();
commands.entity(parent).add_child(child);
```
When that could just be
```rust
commands.spawn(..).set_parent(parent);
```

Adding `set_parent` was trivial as it's just an `AddChild` command. Most of the changes are for `remove_parent`.
Also updated some outdated docs.

Co-authored-by: devil-ira <[email protected]>
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events and removed A-Hierarchy labels Jan 28, 2025
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-Docs An addition or correction to our documentation C-Usability A targeted quality-of-life change that makes Bevy easier to use 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.

5 participants