Skip to content

Commit 4610261

Browse files
authored
Migration writing pass 5 (#2094)
1 parent 5a928fc commit 4610261

10 files changed

+68
-52
lines changed

release-content/0.16/migration-guides/15624_Support_using_FilteredResources_with_ReflectResource.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
The order of hooks and observers for `on_replace` and `on_remove` has been swapped. Observers are now run before hooks. This is a more natural ordering where the removal ordering is inverted compared to the insertion ordering.
1+
The order of hooks and observers for `on_replace()` and `on_remove()` has been swapped, so now observers are run before hooks. As hooks are more primitive, they are designated as the first and last thing run when a component is added and removed. The total order for component removal can now be seen in the following table:
2+
3+
|0.15|0.16|
4+
|-|-|
5+
|`on_replace()` hook|`on_replace()` observer|
6+
|`on_replace()` observer|`on_replace()` hook|
7+
|`on_remove()` hook|`on_remove()` observer|
8+
|`on_remove()` observer|`on_remove()` hook|
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- If you were previously calling the special `apply_deferred` system via `apply_deferred(world)`, don’t.
1+
The special `apply_deferred()` system has been converted into the zero-sized `ApplyDeferred` type that implements `System` for performance reasons. If you manually schedule `apply_deferred()`, which usually isn't the case, you will need to use the new `ApplyDeferred` type instead. If you manually called `apply_deferred()` without your code, you may delete it, as that function did nothing.
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
`EntityHashSet` and `EntityHashMap` are no longer re-exported in `bevy_ecs::entity` directly. If you were not using `bevy_ecs` / `bevy`’s `prelude`, you can access them through their now-public modules, `hash_set` and `hash_map` instead.
1+
`EntityHashSet` and `EntityHashMap` are no longer re-exported in `bevy::ecs::entity`, although they are still accessible through the prelude. If you were directly importing `EntityHashSet` and `EntityHashMap`, please access them from `bevy::ecs::entity::hash_set` and `bevy::ecs::entity::hash_map`.
2+
3+
```rust
4+
// 0.15
5+
use bevy::ecs::entity::{HashSet, HashMap};
6+
7+
// 0.16
8+
use bevy::ecs::entity::{hash_set::HashSet, hash_map::HashMap};
9+
```
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
`Component::register_component_hooks` is now deprecated and will be removed in a future release. When implementing `Component` manually, also implement the respective hook methods on `Component`.
1+
Component hook registration is now split out into individual methods of `Component`. The original `Component::register_component_hooks()` has been deprecated, so please switch to the new `Component::on_add()`, `Component::on_remove()`, and related methods.
22

33
```rust
4-
// Before
4+
// 0.15
55
impl Component for Foo {
6-
// snip
76
fn register_component_hooks(hooks: &mut ComponentHooks) {
8-
hooks.on_add(foo_on_add);
7+
hooks.on_add(foo_on_add);
98
}
9+
10+
// ...
1011
}
1112

12-
// After
13+
// 0.16
1314
impl Component for Foo {
14-
// snip
1515
fn on_add() -> Option<ComponentHook> {
16-
Some(foo_on_add)
16+
Some(foo_on_add)
1717
}
18+
19+
// ...
1820
}
1921
```
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Users of `QueryLens::query()` who were calling `get_inner()` or `iter_inner()` will need to replace the call with `QueryLens::query_inner()`.
1+
There was a lifetime issue found with `QueryLens::query()` where calling `get_inner()` on the returned value would allow for multiple mutable references to the same entity. This has been fixed by shrinking the lifetime of `QueryLens::query()`'s result, however it may break existing code.
2+
3+
If you run into lifetime issues while calling `get_inner()` or `iter_inner()` on `QueryLens::query()`'s result, you may need to switch to the new `QueryLens::query_inner()` method that only works on immutable queries.
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
- `EventWriter::send` has been renamed to `EventWriter::write`.
2-
- `EventWriter::send_batch` has been renamed to `EventWriter::write_batch`.
3-
- `EventWriter::send_default` has been renamed to `EventWriter::write_default`.
1+
`EventWriter::send()` and its family of methods have been renamed to `EventWriter::write()` in order to reduce confusion and increase consistency. The old methods have been deprecated.
2+
3+
|0.15|0.16|
4+
|-|-|
5+
|`EventWriter::send()`|`EventWriter::write()`|
6+
|`EventWriter::send_batch()`|`EventWriter::write_batch()`|
7+
|`EventWriter::send_default()`|`EventWriter::write_default()`|
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
`RequiredComponents::register_dynamic` has been changed to `RequiredComponents::register_dynamic_with`.
2-
3-
Old:
1+
`RequiredComponents::register_dynamic()` has been replaced by `RequiredComponents::register_dynamic_with()`, which avoids unnecessary cloning.
42

53
```rust
4+
// 0.15
65
required_components.register_dynamic(
7-
component_id,
8-
component_constructor.clone(),
9-
requirement_inheritance_depth,
6+
component_id,
7+
component_constructor.clone(),
8+
requirement_inheritance_depth,
109
);
11-
```
12-
13-
New:
1410

15-
```rust
11+
// 0.16
1612
required_components.register_dynamic_with(
17-
component_id,
18-
requirement_inheritance_depth,
19-
|| component_constructor.clone(),
13+
component_id,
14+
requirement_inheritance_depth,
15+
|| component_constructor.clone(),
2016
);
2117
```
22-
23-
This can prevent unnecessary cloning.
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
If you were previously implementing `VisitEntities` or `VisitEntitiesMut` (likely via a derive), instead use `MapEntities`. Those were almost certainly used in the context of Bevy Scenes or reflection via `ReflectMapEntities`. If you have a case that uses `VisitEntities` or `VisitEntitiesMut` directly, where `MapEntities` is not a viable replacement, please let us know!
1+
`VisitEntities` and `VisitEntitiesMut` have been removed in favor of `MapEntities`, as the prior is less generally applicable (doesn't work on collections like `HashSet`s). If you previously derived `VisitEntities` and family, you can now derive `MapEntities` and use the `#[entities]` attribute to annotate the list of `Entity`s.
22

33
```rust
4-
// before
4+
// 0.15
55
#[derive(VisitEntities, VisitEntitiesMut)]
66
struct Inventory {
7-
items: Vec<Entity>,
8-
#[visit_entities(ignore)]
9-
label: String,
7+
items: Vec<Entity>,
8+
// Opt-out of mapping this field, as its a string.
9+
#[visit_entities(ignore)]
10+
label: String,
1011
}
1112

12-
// after
13+
// 0.16
1314
#[derive(MapEntities)]
1415
struct Inventory {
15-
#[entities]
16-
items: Vec<Entity>,
17-
label: String,
16+
// Opt-in to mapping this field.
17+
#[entities]
18+
items: Vec<Entity>,
19+
label: String,
1820
}
1921
```
22+
23+
Note `Component::visit_entities()` and `Component::visit_entities_mut()` have also been removed in favor of the new `Component::map_entities()` method. When deriving `Component`, you may also use `#[entities]` to specify which `Entity`s may be mapped.
24+
25+
Finally, entity mapping is no longer implemented for all types that implement `IntoIterator<Item = &Entity>`. If you previously depended on a custom data type to support the `#[entities]` attribute, please manually derive / implement `MapEntities` for it.

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ areas = ["ECS"]
317317
file_name = "16911_Remove_unused_generic_in_DeferredWorldtrigger.md"
318318

319319
[[guides]]
320-
title = "Renamed `EventWriter::send` methods to `write`."
320+
title = "Rename `EventWriter::send()` methods to `write()`"
321321
prs = [17977]
322322
areas = ["ECS"]
323323
file_name = "17977_Renamed_EventWritersend_methods_to_write.md"
@@ -329,43 +329,37 @@ areas = ["ECS"]
329329
file_name = "18432_Replace_VisitEntities_with_MapEntities.md"
330330

331331
[[guides]]
332-
title = "Run observers before hooks for `on_replace` and `on_remove`"
332+
title = "Run observers before hooks for `on_replace()` and `on_remove()`"
333333
prs = [16499]
334334
areas = ["ECS"]
335335
file_name = "16499_Run_observers_before_hooks_for_on_replace_and_on_remove.md"
336336

337337
[[guides]]
338-
title = "Shorten the 'world lifetime returned from `QueryLens::query()`."
338+
title = "Shorten the lifetime returned from `QueryLens::query()`"
339339
prs = [17694]
340340
areas = ["ECS"]
341341
file_name = "17694_Shorten_the_world_lifetime_returned_from_QueryLensquery.md"
342342

343343
[[guides]]
344-
title = "Split `Component::register_component_hooks` into individual methods"
344+
title = "Split `Component::register_component_hooks()` into individual methods"
345345
prs = [17685]
346346
areas = ["ECS"]
347347
file_name = "17685_Split_Componentregister_component_hooks_into_individual_me.md"
348348

349349
[[guides]]
350-
title = "Support non-Vec data structures in relations"
350+
title = "Don't re-export `EntityHashSet` and `EntityHashMap`"
351351
prs = [17447]
352352
areas = ["ECS"]
353353
file_name = "17447_Support_nonVec_data_structures_in_relations.md"
354354

355355
[[guides]]
356-
title = "Support using FilteredResources with ReflectResource."
357-
prs = [15624]
358-
areas = ["ECS"]
359-
file_name = "15624_Support_using_FilteredResources_with_ReflectResource.md"
360-
361-
[[guides]]
362-
title = "Turn `apply_deferred` into a ZST System"
356+
title = "Turn `apply_deferred()` into a ZST system"
363357
prs = [16642]
364358
areas = ["ECS"]
365359
file_name = "16642_Turn_apply_deferred_into_a_ZST_System.md"
366360

367361
[[guides]]
368-
title = "Use register_dynamic for merging"
362+
title = "Replace `register_dynamic()` with `register_dynamic_with()`"
369363
prs = [18028]
370364
areas = ["ECS"]
371365
file_name = "18028_Use_register_dynamic_for_merging.md"

0 commit comments

Comments
 (0)