bevyengine / bevyengine/bevy

Add `EntityWorldMut::commands` method

Open
#14,278 3 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Feature S-Ready-For-Implementation
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?

I'm implementing UI widgets as `EntityCommand`s to get an API like this:

```rust
commands.spawn_empty().add(my_ui_widget).insert(Name::new("CustomName"))
```

I want my parent widget to create child widgets with `entity.add(my_child_widget)`, but `entity` is an `EntityWorldMut`, not an `EntityCommands`, so it has no `.add` method.

## What solution would you like?

```rust
fn my_parent_widget(mut entity: EntityWorldMut) {
entity.commands().add(my_child_widget).insert(...);
}
```

This is a natural solution, because `EntityWorldMut::commands -> EntityCommands` would parallel `World::commands -> Commands`.

## What alternative(s) have you considered?

1. `EntityWorldMut::add`:

```rust
fn my_parent_widget(mut entity: EntityWorldMut) {
entity.add(my_child_widget).insert(...);
}
```

2. Just work around it:

```rust
fn my_parent_widget(mut entity: EntityWorldMut) {
{
let id = entity.id();
entity.world_scope(|world| world.commands().add(my_child_widget.with_entity(id)));
}
entity.insert(...);
}
```

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.