Skip to content

Commit 36e748e

Browse files
Improve code examples in 0.18 migration guides (#22364)
> [!IMPORTANT] > This PR targets the `release-0.18.0` branch, not `main`. # Objective - Bevy 0.18 is close to release! Let's do a review pass over the migration guides. ## Solution - Make code block examples consistent by [following the style guide](https://github.com/bevyengine/bevy/blob/e457025cc447a9c36ac452f89c3da9ef836cd0d5/release-content/migration_guides.md?plain=1#L75-L90). - Clarify that `bevy_input`'s input-type features (`keyboard`, `gamepad`, etc.) are also available on the main `bevy` crate. - Improve the system combinator migration guide, as I found it quite confusing. - Add PR numbers to migration guides that are missing them. ## Testing I tested that the system combinator migration guide code examples worked in the relevant versions, but didn't test any of the others because I didn't modify any of their actual code. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent 628f6d4 commit 36e748e

25 files changed

+145
-152
lines changed

release-content/migration-guides/ambient_light_split.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ The resource `GlobalAmbientLight` is the default ambient light for the entire wo
99
Meanwhile, `AmbientLight` is a component that can be added to a `Camera` in order to override the default `GlobalAmbientLight`.
1010
When appropriate, rename `AmbientLight` to `GlobalAmbientLight`.
1111

12-
Before:
13-
1412
```rust
13+
// 0.17
1514
app.insert_resource(AmbientLight {
1615
color: Color::WHITE,
1716
brightness: 2000.,
1817
..default()
1918
});
20-
```
2119

22-
After:
23-
24-
```rust
20+
// 0.18
2521
app.insert_resource(GlobalAmbientLight {
2622
color: Color::WHITE,
2723
brightness: 2000.,

release-content/migration-guides/animation-target-refactor.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ The `AnimationTarget` component has been split into two separate components.
1010
This change was made to add flexibility. It's now possible to calculate the
1111
`AnimationTargetId` first, but defer the choice of player until later.
1212

13-
Before:
14-
1513
```rust
14+
// 0.17
1615
entity.insert(AnimationTarget { id: AnimationTargetId(id), player: player_entity });
17-
```
1816

19-
After:
20-
21-
```rust
17+
// 0.18
2218
entity.insert((AnimationTargetId(id), AnimatedBy(player_entity)));
2319
```

release-content/migration-guides/archetype_query_data.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Code that requires queries to `impl ExactSizeIterator` may need to replace `Quer
1515
fn requires_exact_size<D: QueryData>(q: Query<D>) -> usize {
1616
q.into_iter().len()
1717
}
18+
1819
// 0.18
1920
fn requires_exact_size<D: ArchetypeQueryData>(q: Query<D>) -> usize {
2021
q.into_iter().len()

release-content/migration-guides/asset_watcher_async_sender.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: AssetSources now give an `async_channel::Sender` instead of a `crossbeam_channel::Sender`
3-
pull_requests: []
3+
pull_requests: [21626]
44
---
55

66
Previously, when creating an asset source, `AssetSourceBuilder::with_watcher` would provide users

release-content/migration-guides/bevy_input_features.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ If you use `bevy_window` or `bevy_gilrs`, they will automatically
1111
enable the necessary features on `bevy_input`. If you don't depend
1212
on them (for example, if you are developing for a platform that
1313
isn't supported by these crates), you need to enable the required
14-
input sources on `bevy_input` manually:
14+
input sources on the `bevy_input` / `bevy` crate manually:
1515

1616
```toml
17-
# Before:
17+
# 0.17
1818
bevy = { version = "0.17", default-features = false }
19-
# After (enable sources that you actually use):
19+
20+
# 0.18 (enable sources that you actually use):
2021
bevy = { version = "0.18", default-features = false, features = [
2122
"mouse",
2223
"keyboard",

release-content/migration-guides/bindgroup-labels-mandatory.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ In previous versions of Bevy, the `label` of a `BindGroupLayout` was optional. T
88
If you were previously omitting the `label` implementation from a `impl AsBindGroup`, you now must implement it:
99

1010
```rust
11-
fn label() -> &'static str {
12-
"my label"
11+
impl AsBindGroup for CoolMaterial {
12+
// ...
13+
14+
fn label() -> &'static str {
15+
// It is customary to make the label the name of the type.
16+
"CoolMaterial"
17+
}
1318
}
1419
```

release-content/migration-guides/bundle_component_ids.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ pull_requests: [14791, 15458, 15269]
66
`Bundle::component_ids` and `Bundle::get_component_ids` were changed to return an iterator over
77
`ComponentId` and `Option<ComponentId>` respectively. In some cases this can avoid allocating.
88

9+
For implementors:
10+
911
```rust
10-
// For implementors
11-
// Before
12+
// 0.17
1213
unsafe impl<C: Component> Bundle for C {
1314
fn component_ids(components: &mut ComponentsRegistrator, ids: &mut impl FnMut(ComponentId)) {
1415
ids(components.register_component::<C>());
@@ -19,7 +20,7 @@ unsafe impl<C: Component> Bundle for C {
1920
}
2021
}
2122

22-
// After
23+
// 0.18
2324
unsafe impl<C: Component> Bundle for C {
2425
fn component_ids<(
2526
components: &mut ComponentsRegistrator,
@@ -34,14 +35,15 @@ unsafe impl<C: Component> Bundle for C {
3435
}
3536
```
3637

38+
For consumers:
39+
3740
```rust
38-
// For Consumers
39-
// Before
41+
// 0.17
4042
let mut components = vec![];
4143
MyBundle::component_ids(&mut world.components_registrator(), &mut |id| {
4244
components.push(id);
4345
});
4446

45-
// After
47+
// 0.18
4648
let components: Vec<_> = B::component_ids(&mut world.components_registrator()).collect();
4749
```

release-content/migration-guides/changed_asset_server_init.md

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,57 +3,36 @@ title: Changes to `AssetServer` and `AssetProcessor` creation.
33
pull_requests: [21763]
44
---
55

6-
Previously `AssetServer`s `new` methods would take `AssetSources`. Now, these methods take
7-
`Arc<AssetSources>`. So if you previously had:
6+
Previously `AssetServer`s `new` and `new_with_method_check` methods would take `AssetSources`. Now, these methods take
7+
`Arc<AssetSources>`.
88

99
```rust
10+
// 0.17
1011
AssetServer::new(
1112
sources,
1213
mode,
1314
watching_for_changes,
1415
unapproved_path_mode,
1516
)
1617

17-
// OR:
18-
AssetServer::new_with_meta_check(
19-
sources,
20-
mode,
21-
meta_check,
22-
watching_for_changes,
23-
unapproved_path_mode,
24-
)
25-
```
26-
27-
Now you need to do:
28-
29-
```rust
18+
// 0.18
3019
AssetServer::new(
20+
// Wrap the sources in an `Arc`.
3121
Arc::new(sources),
3222
mode,
3323
watching_for_changes,
3424
unapproved_path_mode,
3525
)
36-
37-
// OR:
38-
AssetServer::new_with_meta_check(
39-
Arc::new(sources),
40-
mode,
41-
meta_check,
42-
watching_for_changes,
43-
unapproved_path_mode,
44-
)
4526
```
4627

4728
`AssetProcessor::new` has also changed. It now returns to you the `Arc<AssetSources>` which can (and
48-
should) be shared with the `AssetServer`. So if you previously had:
29+
should) be shared with the `AssetServer`.
4930

5031
```rust
32+
// 0.17
5133
let processor = AssetProcessor::new(sources);
52-
```
5334

54-
Now you need:
55-
56-
```rust
35+
// 0.18
5736
let (processor, sources_arc) = AssetProcessor::new(
5837
sources,
5938
// A bool whether the returned sources should listen for changes as asset processing completes.

release-content/migration-guides/combinator_system.md

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,41 @@ title: System Combinators
33
pull_requests: [20671]
44
---
55

6-
The `CombinatorSystem`s can be used to combine multiple `SystemCondition`s with logical operators. Previously, the conditions would short circuit if the system failed to run, for example because it's query could not be filled by the world.
6+
`CombinatorSystem`s can be used to combine multiple `SystemCondition`s with logical operators (such as `and`, `or`, and `xor`). Previously, these combinators would propagate any errors made when running the combined systems:
77

8-
Now, the `CombinatorSystem`s will work as expected, following the semantics of rust's logical operators.
9-
Namely, if a `SystemCondition` fails, it will be considered to have returned `false` and in combinators that don't short circuit the other condition will now be run.
8+
```rust
9+
// 0.17
10+
#[derive(Component)]
11+
struct Foo;
12+
13+
// This run condition will fail validation because there is not an entity with `Foo` in the world.
14+
fn fails_validation(_: Single<&Foo>) -> bool {
15+
// ...
16+
}
17+
18+
fn always_true() -> bool {
19+
true
20+
}
21+
22+
let mut world = World::new();
1023

11-
Specifically, the combinators act as follows:
24+
// Because `fails_validation` is invalid, trying to run this combinator system will return an
25+
// error.
26+
assert!(world.run_system_once(fails_validation.or(always_true)).is_err());
27+
```
28+
29+
This behavior has been changed in Bevy 0.18. Now if one of the combined systems fails, it will be considered to have returned `false`. The error will not be propagated, and the combinator logic will continue:
30+
31+
```rust
32+
// 0.18
33+
let mut world = World::new();
34+
35+
// `fails_validation` is invalid, but it is converted to `false`. Because `always_true` succeeds,
36+
// the combinator returns `true`.
37+
assert_eq!(matches!(world.run_system_once(fails_validation.or(always_true)), Ok(true)));
38+
```
39+
40+
This affects the following combinators:
1241

1342
| Combinator | Rust Equivalent |
1443
|:----------:|:---------------:|
@@ -18,21 +47,3 @@ Specifically, the combinators act as follows:
1847
| `nand` | `!(a && b)` |
1948
| `nor` | `!(a \|\| b)` |
2049
| `xnor` | `!(a ^ b)` |
21-
22-
```rust
23-
fn vacant(_: crate::system::Single<&Vacant>) -> bool {
24-
true
25-
}
26-
27-
fn is_true() -> bool {
28-
true
29-
}
30-
31-
assert!(world.query::<&Vacant>().iter(&world).next().is_none());
32-
33-
// previously:
34-
assert!(world.run_system_once(is_true.or(vacant)).is_err());
35-
36-
// now:
37-
assert!(matches!(world.run_system_once(is_true.or(vacant)), Ok(true)));
38-
```

release-content/migration-guides/custom_asset_source_infallible.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,17 @@ Previously, it was possible to create asset sources with no reader, resulting in
77
silently being skipped. This is no longer possible, since `AssetSourceBuilder` must now be given a
88
reader to start. We also slightly changed how sources are expected to be built.
99

10-
In previous versions, creating a custom source would look like:
11-
1210
```rust
11+
// 0.17
1312
AssetSource::build()
14-
.with_reader(move || todo!("the reader!"))
15-
.with_writer(move || todo!())
16-
.with_processed_reader(move || todo!())
17-
.with_processed_writer(move || todo!())
18-
```
13+
.with_reader(move || /* reader logic */)
14+
.with_writer(move || /* ... */)
15+
.with_processed_reader(move || /* ... */)
16+
.with_processed_writer(move || /* ... */);
1917

20-
In Bevy 0.18, this now looks like:
21-
22-
```rust
23-
// You may need to import AssetSourceBuilder.
24-
AssetSourceBuilder::new(move || todo!("the reader!"))
25-
.with_writer(move || todo!())
26-
.with_processed_reader(move || todo!())
27-
.with_processed_writer(move || todo!())
18+
// 0.18
19+
AssetSourceBuilder::new(move || /* reader logic */)
20+
.with_writer(move || /* ... */)
21+
.with_processed_reader(move || /* ... */)
22+
.with_processed_writer(move || /* ... */;
2823
```

0 commit comments

Comments
 (0)