bevyengine / bevyengine/bevy

Despawn entities on relationship component removal when linked spawn is enabled

Open
#20,252 6 comments 3 reactions 0 assignees View on GitHub
A-ECS C-Bug D-Modest S-Needs-Design X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

The following code works:

```rust
let mut world = World::new();

let mut entity = world.spawn((
Name::new("Root"),
children![Name::new("Child1"), Name::new("Child2"),],
));

entity.remove::();

assert_eq!(world.entities().len(), 3);
```

But I'm not sure if this behavior is expected/desired. This makes it easy for users to "leak" entities.

## What solution would you like?

We have [RelationshipTarget::LINKED_SPAWN](https://docs.rs/bevy/latest/bevy/prelude/trait.RelationshipTarget.html#associatedconstant.LINKED_SPAWN) which works for despawn and cloning. I'd suggest to extend it to the relationship target component removal.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.