Skip to content

Commit 398fb88

Browse files
Migration guide for EntityCommands::apply (#2069)
Co-authored-by: JaySpruce <[email protected]>
1 parent 081e015 commit 398fb88

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
The `EntityCommands::apply` method now takes an `EntityWorldMut` argument, instead of an `Entity` and a `&mut World` argument.
2+
This was done to improve our error handling and better encapsulate the effect of `EntityCommands`, which are focused on mutating a single entity during exclusive world access.
3+
4+
To access the entity affected, use `EntityWorldMut::id`. Before:
5+
6+
```rust
7+
struct Foo;
8+
9+
impl EntityCommand for Foo {
10+
fn apply(self, entity: Entity, world: &mut World) {
11+
world
12+
.run_system_cached_with(print_entity, entity)
13+
.unwrap();
14+
}
15+
}
16+
17+
fn print_entity(In(entity): In<Entity>) {
18+
info!("entity: {entity}");
19+
}
20+
```
21+
22+
After:
23+
24+
```rust
25+
struct Foo;
26+
27+
impl EntityCommand for Foo {
28+
fn apply(self, entity_world: EntityWorldMut) {
29+
let entity = entity_world.id();
30+
entity_world
31+
.into_world_mut()
32+
.run_system_cached_with(print_entity, entity)
33+
.unwrap();
34+
}
35+
}
36+
37+
fn print_entity(In(entity): In<Entity>) {
38+
info!("entity: {entity}");
39+
}
40+
```
41+
42+
While `EntityWorldMut` has most of the same methods as `&mut World`, you can transform it into `&mut World` by calling `EntityWorldMut::into_world_mut`.

release-content/0.16/migration-guides/_guides.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ prs = [16589, 18541, 18666]
166166
areas = ["ECS"]
167167
file_name = "16589_Fallible_systems.md"
168168

169+
[[guides]]
170+
title = "`EntityCommands::apply` now takes an `EntityWorldMut` argument"
171+
prs = [17215]
172+
areas = ["ECS"]
173+
file_name = "EntityCommands_apply_signature.md"
174+
169175
[[guides]]
170176
title = "Fix unsoundness in `QueryIter::sort_by`"
171177
prs = [17826]

0 commit comments

Comments
 (0)