-
Notifications
You must be signed in to change notification settings - Fork 352
/
_index.md
1533 lines (1115 loc) · 58.7 KB
/
_index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
+++
title = "0.11 to 0.12"
weight = 7
sort_by = "weight"
template = "docs-section.html"
page_template = "docs-section.html"
insert_anchor_links = "right"
[extra]
long_title = "Migration Guide: 0.11 to 0.12"
+++
Bevy relies heavily on improvements in the Rust language and compiler.
As a result, the Minimum Supported Rust Version (MSRV) is "the latest stable release" of Rust.
<div class="migration-guide">
### [API updates to the AnimationPlayer](https://github.com/bevyengine/bevy/pull/9002)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Animation</div>
</div>
Some methods on [`AnimationPlayer`](https://docs.rs/bevy/0.12.0/bevy/animation/struct.AnimationPlayer.html) have changed.
- `elapsed` was removed. Use `seek_time`.
- `set_elapsed` was removed. Use `seek_to`.
- `stop_repeating` was removed. Use `set_repeat(RepeatAnimation::Never)`.
If you were manually resetting animation state, you can use the new `replay` method instead.
### [Fix run-once runners](https://github.com/bevyengine/bevy/pull/10195)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">App</div>
</div>
`app.ready()` has been replaced by `app.plugins_state()` which will return more details on the current state of plugins in the app
### [Add support for KHR_materials_emissive_strength](https://github.com/bevyengine/bevy/pull/9553)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Assets</div>
</div>
The GLTF asset loader will now factor in `emissiveStrength` when converting to Bevy’s `StandardMaterial::emissive`. Blender will export emissive materials using this field. Remove the field from your GLTF files or manually modify your materials post-asset-load to match how Bevy would load these files in previous versions.
### [Bevy Asset V2](https://github.com/bevyengine/bevy/pull/8624)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Assets</div>
</div>
#### Migrating a custom asset loader
Existing asset loaders will need a few small changes to get them to work with Bevy Assets V2.
First, you’ll need to add the asset type as an associated type of the loader. This type is called `Asset` and represents the type of the “default asset” produced by the loader.
You’ll also need to add a `Settings` type which represents options that can be passed to the loader when you request an asset. If your asset has no settings, then you can just set it to the unit type.
```rust
pub struct MyAssetLoader;
impl AssetLoader for MyAssetLoader {
type Asset = MyAsset;
type Settings = ();
```
You’ll need to make a couple small changes to the `load` function as well. The load function now takes a `settings` parameter whose type is, you guessed it, `Settings`:
```rust
fn load<'a>(
&'a self,
reader: &'a mut Reader,
settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, anyhow::Error>> {
```
Again, if you are not using settings, then you can just ignore the parameter (prefix it with “_”).
Also, the second argument is now a reader rather than vector of bytes. If your existing code expects bytes, you can simply read the entire stream:
```rust
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, anyhow::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
```
Finally, you’ll need to write the code which returns the default asset. This used to be done via a call to `load_context.set_default_asset()`, however in V2 you simply return the asset from the `load` function:
```rust
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, anyhow::Error>> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let mut asset: MyAsset =
serde_json::from_slice(&bytes).expect("unable to decode asset");
Ok(asset)
}
```
To use the new loader, make sure you register both the loader and the asset type:
```rust
app.register_asset_loader(MyAssetLoader)
.init_asset::<MyAsset>()
```
#### Labeled assets
If your loader allows labeled assets, there are a couple of different ways to handle them. The simplest is to call `load_context.labeled_asset_scope`:
```rust
// Assume `asset.children` is a HashMap or something.
// Using `drain` here so that we take ownership and don't end up with
// multiple references to the same asset.
asset.children.drain().for_each(|(label, mut item)| {
load_context.labeled_asset_scope(label, |lc| {
// Do any additional processing on the item
// Use 'lc' to load dependencies
item
});
});
```
You can use the provided load context (`lc`) to load additional assets. These will automatically be registered as dependencies of the labeled asset.
#### Using assets
The actual call to `load` hasn’t changed:
```rust
let handle = server.load("path/to/my/asset.json");
// ...
let data = assets.get(&handle).unwrap();
```
#### Asset events
There are a few changes to asset events. The event no longer contains a `handle` field, instead the event contains a field called `id`:
```rust
for ev in ev_template.read() {
match ev {
AssetEvent::Added { id } => {
println!("Asset added");
}
AssetEvent::LoadedWithDependencies { id } => {
println!("Asset loaded");
}
AssetEvent::Modified { id } => {
println!("Asset modified");
}
AssetEvent::Removed { id } => {
println!("Asset removed");
}
}
}
```
The `id` can be used to get access to the asset data, the asset’s path or load status. Asset handles also contain an `id` field which can be used to compare for equality:
```rust
AssetEvent::Modified { id } => {
for cmp in query.iter() {
if cmp.handle.id() == id {
println!("Found it!");
}
}
}
```
Also, as you may have noticed, the set of events has changed. The most important of these is `LoadedWithDependencies` which tells you that the asset and all its dependencies have finished loading into memory.
### [Copy on Write AssetPaths](https://github.com/bevyengine/bevy/pull/9729)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Assets</div>
</div>
```rust
// 0.11
AssetPath::new("logo.png", None);
// 0.12
AssetPath::from("logo.png");
// 0.11
AssetPath::new("scene.gltf", Some("Mesh0"));
// 0.12
AssetPath::from("scene.gltf").with_label("Mesh0");
```
`AssetPath` now serializes as `AssetPath("some_path.extension#Label")` instead of as `AssetPath { path: "some_path.extension", label: Some("Label) }`
### [Removed `anyhow`](https://github.com/bevyengine/bevy/pull/10003)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Assets</div>
</div>
- `anyhow` is no longer exported by `bevy_asset`; Add it to your own project (if required).
- `AssetLoader` and `AssetSaver` have an associated type `Error`; Define an appropriate error type (e.g., using `thiserror`), or use a pre-made error type (e.g., `anyhow::Error`). Note that using `anyhow::Error` is a drop-in replacement.
- `AssetLoaderError` has been removed; Define a new error type, or use an alternative (e.g., `anyhow::Error`)
- All the first-party `AssetLoader`s and `AssetSaver`s now return relevant (and narrow) error types instead of a single ambiguous type; Match over the specific error type, or encapsulate (`Box<dyn>`, `thiserror`, `anyhow`, etc.)
### [Non-blocking load_untyped using a wrapper asset](https://github.com/bevyengine/bevy/pull/10198)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Assets</div>
</div>
Whenever possible use the typed API in order to directly get a handle to your asset. If you do not know the type or need to use `load_untyped` for a different reason, Bevy 0.12 introduces an additional layer of indirection. The asset server will return a handle to a `LoadedUntypedAsset`, which will load in the background. Once it is loaded, the untyped handle to the asset file can be retrieved from the `LoadedUntypedAsset`s field `handle`.
### [reflect: `TypePath` part 2](https://github.com/bevyengine/bevy/pull/8768)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Assets</div>
<div class="migration-guide-area-tag">Reflection</div>
</div>
- Rely on `TypePath` instead of `std::any::type_name` for all stability guarantees and for use in all reflection contexts, this is used through with one of the following APIs:
- `TypePath::type_path` if you have a concrete type and not a value.
- `DynamicTypePath::reflect_type_path` if you have an `dyn Reflect` value without a concrete type.
- `TypeInfo::type_path` for use through the registry or if you want to work with the represented type of a `DynamicFoo`.
- Remove `type_name` from manual `Reflect` implementations.
- Use `type_path` and `type_path_table` in place of `type_name` on `TypeInfo`-like structs.
- Use `get_with_type_path(_mut)` over `get_with_type_name(_mut)`.
### [More ergonomic spatial audio](https://github.com/bevyengine/bevy/pull/9800)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Audio</div>
</div>
Spatial audio now automatically uses the transform of the `AudioBundle` and of an entity with a `SpatialListener` component.
If you were manually scaling emitter/listener positions, you can use the `spatial_scale` field of `AudioPlugin` instead.
```rust
// 0.11
commands.spawn(
SpatialAudioBundle {
source: asset_server.load("sounds/Windless Slopes.ogg"),
settings: PlaybackSettings::LOOP,
spatial: SpatialSettings::new(listener_position, gap, emitter_position),
},
);
fn update(
emitter_query: Query<(&Transform, &SpatialAudioSink)>,
listener_query: Query<&Transform, With<Listener>>,
) {
let listener = listener_query.single();
for (transform, sink) in &emitter_query {
sink.set_emitter_position(transform.translation);
sink.set_listener_position(*listener, gap);
}
}
// 0.12
commands.spawn((
SpatialBundle::from_transform(Transform::from_translation(emitter_position)),
AudioBundle {
source: asset_server.load("sounds/Windless Slopes.ogg"),
settings: PlaybackSettings::LOOP.with_spatial(true),
},
));
commands.spawn((
SpatialBundle::from_transform(Transform::from_translation(listener_position)),
SpatialListener::new(gap),
));
```
### [Simplify parallel iteration methods](https://github.com/bevyengine/bevy/pull/8854)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
The method `QueryParIter::for_each_mut` has been deprecated and is no longer functional. Use `for_each` instead, which now supports mutable queries.
```rust
// 0.11
query.par_iter_mut().for_each_mut(|x| ...);
// 0.12
query.par_iter_mut().for_each(|x| ...);
```
The method `QueryParIter::for_each` now takes ownership of the `QueryParIter`, rather than taking a shared reference.
```rust
// 0.11
let par_iter = my_query.par_iter().batching_strategy(my_batching_strategy);
par_iter.for_each(|x| {
// ...Do stuff with x...
par_iter.for_each(|y| {
// ...Do nested stuff with y...
});
});
// 0.12
my_query.par_iter().batching_strategy(my_batching_strategy).for_each(|x| {
// ...Do stuff with x...
my_query.par_iter().batching_strategy(my_batching_strategy).for_each(|y| {
// ...Do nested stuff with y...
});
});
```
### [Fix safety invariants for `WorldQuery::fetch` and simplify cloning](https://github.com/bevyengine/bevy/pull/8246)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
**`fetch` invariants**
The function `WorldQuery::fetch` has had the following safety invariant added:
> If `update_component_access` includes any mutable accesses, then the caller must ensure that `fetch` is called no more than once for each `entity`/`table_row` in each archetype.
> </br>
> If `Self` implements `ReadOnlyWorldQuery`, then this can safely be called multiple times.
This invariant was always required for soundness, but was previously undocumented. If you called this function manually anywhere, you should check to make sure that this invariant is not violated.
**Removed `clone_fetch`**
The function `WorldQuery::clone_fetch` has been removed. The associated type `WorldQuery::Fetch` now has the bound `Clone`.
```rust
// 0.11
struct MyFetch<'w> { ... }
unsafe impl WorldQuery for MyQuery {
...
type Fetch<'w> = MyFetch<'w>
unsafe fn clone_fetch<'w>(fetch: &Self::Fetch<'w>) -> Self::Fetch<'w> {
MyFetch {
field1: fetch.field1,
field2: fetch.field2.clone(),
...
}
}
}
// 0.12
#[derive(Clone)]
struct MyFetch<'w> { ... }
unsafe impl WorldQuery for MyQuery {
...
type Fetch<'w> = MyFetch<'w>;
}
```
### [Opt-out `multi-threaded` feature flag](https://github.com/bevyengine/bevy/pull/9269)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
The `multi-threaded` feature in `bevy_ecs` and `bevy_tasks` is no longer enabled by default. However, this remains a default feature for the umbrella `bevy` crate. If you depend on `bevy_ecs` or `bevy_tasks` directly, you should consider enabling this to allow systems to run in parallel.
### [Refactor build_schedule and related errors](https://github.com/bevyengine/bevy/pull/9579)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
`ScheduleBuildError` now has strings in more of its variants. You may need to adjust code that is handling these variants.
### [Add `system.map(...)` for transforming the output of a system](https://github.com/bevyengine/bevy/pull/8526)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
The `system_adapter` functions have been deprecated: use `.map` instead, which is a lightweight alternative to `.pipe`.
```rust
// 0.11
my_system.pipe(system_adapter::ignore)
my_system.pipe(system_adapter::unwrap)
my_system.pipe(system_adapter::new(T::from))
// 0.12
my_system.map(std::mem::drop)
my_system.map(Result::unwrap)
my_system.map(T::from)
// 0.11
my_system.pipe(system_adapter::info)
my_system.pipe(system_adapter::dbg)
my_system.pipe(system_adapter::warn)
my_system.pipe(system_adapter::error)
// 0.12
my_system.map(bevy_utils::info)
my_system.map(bevy_utils::dbg)
my_system.map(bevy_utils::warn)
my_system.map(bevy_utils::error)
```
### [Replaced EntityMap with HashMap](https://github.com/bevyengine/bevy/pull/9461)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
- Calls to `EntityMap::world_scope` can be directly replaced with the following:
`map.world_scope(&mut world)` -> `world.world_scope(&mut map)`
- Calls to legacy `EntityMap` methods such as `EntityMap::get` must explicitly include de/reference symbols:
`let entity = map.get(parent);` -> `let &entity = map.get(&parent);`
### [Rename `ManualEventIterator`](https://github.com/bevyengine/bevy/pull/9592)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
The type `ManualEventIterator` has been renamed to `EventIterator`. Additionally, `ManualEventIteratorWithId` has been renamed to `EventIteratorWithId`.
### [Replaced `EntityCommand` Implementation for `FnOnce`](https://github.com/bevyengine/bevy/pull/9604)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
**1. New-Type `FnOnce`**
Create an `EntityCommand` type which implements the method you previously wrote:
```rust
pub struct ClassicEntityCommand<F>(pub F);
impl<F> EntityCommand for ClassicEntityCommand<F>
where
F: FnOnce(Entity, &mut World) + Send + 'static,
{
fn apply(self, id: Entity, world: &mut World) {
(self.0)(id, world);
}
}
commands.add(ClassicEntityCommand(|id: Entity, world: &mut World| {
/* ... */
}));
```
**2. Extract `(Entity, &mut World)` from `EntityMut`**
The method `into_world_mut` can be used to gain access to the `World` from an `EntityMut`.
```rust
let old = |id: Entity, world: &mut World| {
/* ... */
};
let new = |mut entity: EntityMut| {
let id = entity.id();
let world = entity.into_world_mut();
/* ... */
};
```
### [Move schedule name into `Schedule`](https://github.com/bevyengine/bevy/pull/9600)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
`Schedule::new` and `App::add_schedule`
```rust
// 0.11
let schedule = Schedule::new();
app.add_schedule(MyLabel, schedule);
// 0.12
let schedule = Schedule::new(MyLabel);
app.add_schedule(schedule);
```
if you aren’t inserting the schedule into the world and are using the schedule directly you can use the default constructor which reuses a default label.
```rust
// 0.11
let schedule = Schedule::new();
schedule.run(world);
// 0.12
let schedule = Schedule::default();
schedule.run(world);
```
`Schedules::insert`
```rust
// 0.11
let schedule = Schedule::new();
schedules.insert(MyLabel, schedule);
// 0.12
let schedule = Schedule::new(MyLabel);
schedules.insert(schedule);
```
`World::add_schedule`
```rust
// 0.11
let schedule = Schedule::new();
world.add_schedule(MyLabel, schedule);
// 0.12
let schedule = Schedule::new(MyLabel);
world.add_schedule(schedule);
```
### [Refactor `EventReader::iter` to `read`](https://github.com/bevyengine/bevy/pull/9631)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
- Existing usages of `EventReader::iter` and `EventReader::iter_with_id` will have to be changed to `EventReader::read` and `EventReader::read_with_id` respectively.
- Existing usages of `ManualEventReader::iter` and `ManualEventReader::iter_with_id` will have to be changed to `ManualEventReader::read` and `ManualEventReader::read_with_id` respectively.
### [Replace `IntoSystemSetConfig` with `IntoSystemSetConfigs`](https://github.com/bevyengine/bevy/pull/9247)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
- Use `App::configure_sets` instead of `App::configure_set`
- Use `Schedule::configure_sets` instead of `Schedule::configure_set`
### [Moved `get_component(_unchecked_mut)` from `Query` to `QueryState`](https://github.com/bevyengine/bevy/pull/9686)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
`use bevy_ecs::system::QueryComponentError;` -> `use bevy_ecs::query::QueryComponentError;`
### [Fix naming on "tick" Column and ComponentSparseSet methods](https://github.com/bevyengine/bevy/pull/9744)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
The following method names were renamed, from `foo_ticks_bar` to `foo_tick_bar` (`ticks` is now singular, `tick`):
- `ComponentSparseSet::get_added_ticks` → `get_added_tick`
- `ComponentSparseSet::get_changed_ticks` → `get_changed_tick`
- `Column::get_added_ticks` → `get_added_tick`
- `Column::get_changed_ticks` → `get_changed_tick`
- `Column::get_added_ticks_unchecked` → `get_added_tick_unchecked`
- `Column::get_changed_ticks_unchecked` → `get_changed_tick_unchecked`
### [Return a boolean from `set_if_neq`](https://github.com/bevyengine/bevy/pull/9801)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
The trait method `DetectChangesMut::set_if_neq` now returns a boolean value indicating whether or not the value was changed. If you were implementing this function manually, you must now return `true` if the value was overwritten and `false` if the value was not.
### [Rename RemovedComponents::iter/iter_with_id to read/read_with_id](https://github.com/bevyengine/bevy/pull/9778)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
```rust
fn react_on_removal(mut removed: RemovedComponents<MyComponent>) {
// 0.11
for entity in removed.iter() { /* ... */ }
for (entity, id) in removed.iter_with_id() { /* ... */ }
for entity in &mut removed { /* ... */ }
// 0.12
for entity in removed.read() { /* ... */ }
for (entity, id) in removed.read_with_id() { /* ... */ }
for entity in removed.read() { /* ... */ }
}
```
### [Remove States::variants and remove enum-only restriction its derive](https://github.com/bevyengine/bevy/pull/9945)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
`States::variants` no longer exists. If you relied on this function, consider using a library that provides enum iterators.
### [Replace all labels with interned labels](https://github.com/bevyengine/bevy/pull/7762)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
</div>
- Replace `BoxedScheduleLabel` and `Box<dyn ScheduleLabel>` with `InternedScheduleLabel` or `Interned<dyn ScheduleLabel>`.
- Replace `BoxedSystemSet` and `Box<dyn SystemSet>` with `InternedSystemSet` or `Interned<dyn SystemSet>`.
- Replace `AppLabelId` with `InternedAppLabel` or `Interned<dyn AppLabel>`.
- Types manually implementing `ScheduleLabel`, `AppLabel` or `SystemSet` need to implement:
- `dyn_hash` directly instead of implementing `DynHash`
- `as_dyn_eq`
- Pass labels to `World::try_schedule_scope`, `World::schedule_scope`, `World::try_run_schedule`. `World::run_schedule`, `Schedules::remove`, `Schedules::remove_entry`, `Schedules::contains`, `Schedules::get` and `Schedules::get_mut` by value instead of by reference.
### [Add configure_schedules to App and Schedules to apply `ScheduleBuildSettings` to all schedules](https://github.com/bevyengine/bevy/pull/9514)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
<div class="migration-guide-area-tag">App</div>
</div>
- No breaking changes.
- Adds `Schedule::get_build_settings()` getter for the schedule’s `ScheduleBuildSettings`.
- Can replaced manual configuration of all schedules:
```rust
// 0.11
for (_, schedule) in app.world.resource_mut::<Schedules>().iter_mut() {
schedule.set_build_settings(build_settings);
}
// 0.l2
app.configure_schedules(build_settings);
```
### [Only run event systems if they have tangible work to do](https://github.com/bevyengine/bevy/pull/7728)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
<div class="migration-guide-area-tag">App</div>
</div>
`Events<T>::update_system` has been split off from the the type and can be found at `bevy_ecs::event::event_update_system`.
### [Allow disjoint mutable world access via `EntityMut`](https://github.com/bevyengine/bevy/pull/9419)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
<div class="migration-guide-area-tag">Reflection</div>
</div>
**Note for maintainers: ensure that the guide for #9604 is updated accordingly.**
Removed the method `EntityRef::world`, to fix a soundness issue with queries. If you need access to `&World` while using an `EntityRef`, consider passing the world as a separate parameter.
`EntityMut` can no longer perform ‘structural’ world mutations, such as adding or removing components, or despawning the entity. Additionally, `EntityMut::world`, `EntityMut::world_mut` , and `EntityMut::world_scope` have been removed.
Instead, use the newly-added type `EntityWorldMut`, which is a helper type for working with `&mut World`.
### [Make builder types take and return `Self`](https://github.com/bevyengine/bevy/pull/10001)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">ECS</div>
<div class="migration-guide-area-tag">Scenes</div>
</div>
When using `bevy_ecs::DynamicSceneBuilder` and `bevy_ecs::SceneBuilder`, instead of binding the builder to a variable, directly use it. Methods on those types now consume `Self`, so you will need to re-bind the builder if you don’t `build` it immediately.
```rust
// 0.11
let mut scene_builder = DynamicSceneBuilder::from_world(&world);
let scene = scene_builder.extract_entity(a).extract_entity(b).build();
// 0.12
let scene = DynamicSceneBuilder::from_world(&world)
.extract_entity(a)
.extract_entity(b)
.build();
```
### [Change `AxisSettings` livezone default](https://github.com/bevyengine/bevy/pull/10090)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Input</div>
</div>
The default live zone bounds have been changed from `-0.95..=0.95` to `-1.0..=1.0` to align with more common usage. If you were relying on the old default, you can change change this by modifying [`GamepadSettings::default_axis_settings`](https://docs.rs/bevy/0.12.0/bevy/input/gamepad/struct.GamepadSettings.html#structfield.default_axis_settings).
### [Rename bevy_math::rects conversion methods](https://github.com/bevyengine/bevy/pull/9159)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Math</div>
</div>
Replace `Rect::as_urect` with `Rect::as_irect`, `Rect::as_rect` with `Rect::as_urect`, and `URect::as_urect` with `URect::as_irect`.
### [Rename `Bezier` to `CubicBezier` for clarity](https://github.com/bevyengine/bevy/pull/9554)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Math</div>
</div>
Change all `Bezier` references to `CubicBezier`
### [Add `Cubic` prefix to all cubic curve generators](https://github.com/bevyengine/bevy/pull/10299)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Math</div>
</div>
- Rename: `BSpline` -> `CubicBSpline`
- Rename: `CardinalSpline` -> `CubicCardinalSpline`
- Rename: `Hermite` -> `CubicHermite`
### [Remove the bevy_dylib feature](https://github.com/bevyengine/bevy/pull/9516)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Meta</div>
</div>
If you were using Bevy’s `bevy_dylib` feature, use Bevy’s `dynamic_linking` feature instead.
```shell
# 0.11
cargo run --features bevy/bevy_dylib
# 0.12
cargo run --features bevy/dynamic_linking
```
```toml
[dependencies]
# 0.11
bevy = { version = "0.11", features = ["bevy_dylib"] }
# 0.12
bevy = { version = "0.12", features = ["dynamic_linking"] }
```
### [Refactor `path` module of `bevy_reflect`](https://github.com/bevyengine/bevy/pull/8887)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Reflection</div>
</div>
If you were matching on the `Err(ReflectPathError)` value returned by `GetPath` and `ParsedPath` methods, now only the parse-related errors and the offset are publicly accessible. You can always use the `fmt::Display` to get a clear error message, but if you need programmatic access to the error types, please open an issue.
### [Make it so `ParsedPath` can be passed to GetPath](https://github.com/bevyengine/bevy/pull/9373)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Reflection</div>
</div>
`GetPath` now requires `Reflect`. This reduces a lot of boilerplate on bevy’s side. If you were implementing manually `GetPath` on your own type, please get in touch!
`ParsedPath::element[_mut]` isn’t an inherent method of `ParsedPath`, you must now import `ReflectPath`. This is only relevant if you weren’t importing the bevy prelude.
```diff
-use bevy::reflect::ParsedPath;
+use bevy::reflect::{ParsedPath, ReflectPath};
parsed_path.element(reflect_type).unwrap()
```
### [Remove TypeRegistry re-export rename](https://github.com/bevyengine/bevy/pull/9807)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Reflection</div>
</div>
- `TypeRegistry` as re-exported by the wrapper `bevy` crate is now `TypeRegistryArc`
- `TypeRegistryInternal` as re-exported by the wrapper `bevy` crate is now `TypeRegistry`
### [Provide getters for fields of ReflectFromPtr](https://github.com/bevyengine/bevy/pull/9748)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Reflection</div>
</div>
- `ReflectFromPtr::as_reflect_ptr` is now `ReflectFromPtr::as_reflect`
- `ReflectFromPtr::as_reflect_ptr_mut` is now `ReflectFromPtr::as_reflect_mut`
### [bevy_reflect: Fix ignored/skipped field order](https://github.com/bevyengine/bevy/pull/7575)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Reflection</div>
</div>
- Fields marked `#[reflect(skip_serializing)]` now must implement `Default` or specify a custom default function with `#[reflect(default = "path::to::some_func")]`
```rust
#[derive(Reflect)]
struct MyStruct {
#[reflect(skip_serializing)]
#[reflect(default = "get_foo_default")]
foo: Foo, // <- `Foo` does not impl `Default` so requires a custom function
#[reflect(skip_serializing)]
bar: Bar, // <- `Bar` impls `Default`
}
#[derive(Reflect)]
struct Foo(i32);
#[derive(Reflect, Default)]
struct Bar(i32);
fn get_foo_default() -> Foo {
Foo(123)
}
```
- `SerializationData::new` has been changed to expect an iterator of `(usize, SkippedField)` rather than one of just `usize`
```rust
// 0.11
SerializationData::new([0, 3].into_iter());
// 0.12
SerializationData::new([
(0, SkippedField::new(field_0_default_fn)),
(3, SkippedField::new(field_3_default_fn)),
].into_iter());
```
- `Serialization::is_ignored_field` has been renamed to `Serialization::is_field_skipped`
- Fields marked `#[reflect(skip_serializing)]` are now included in deserialization output. This may affect logic that expected those fields to be absent.
### [Return URect instead of (UVec2, UVec2) in Camera::physical_viewport_rect](https://github.com/bevyengine/bevy/pull/9085)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Rendering</div>
</div>
```rust
// 0.11
fn view_physical_camera_rect(camera_query: Query<&Camera>) {
let camera = camera_query.single();
let Some((min, max)) = camera.physical_viewport_rect() else { return };
dbg!(min, max);
}
// 0.12
fn view_physical_camera_rect(camera_query: Query<&Camera>) {
let camera = camera_query.single();
let Some(URect { min, max }) = camera.physical_viewport_rect() else { return };
dbg!(min, max);
}
```
### [Update `bevy_window::PresentMode` to mirror `wgpu::PresentMode`](https://github.com/bevyengine/bevy/pull/9230)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Rendering</div>
</div>
Handle `bevy_window::PresentMode::FifoRelaxed` when tweaking window present mode manually.
### [Use GpuArrayBuffer for MeshUniform](https://github.com/bevyengine/bevy/pull/9254)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Rendering</div>
</div>
Accessing the `model` member of an individual mesh object’s shader `Mesh` struct the old way where each `MeshUniform` was stored at its own dynamic offset:
```rust
struct Vertex {
@location(0) position: vec3<f32>,
};
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
out.clip_position = mesh_position_local_to_clip(
mesh.model,
vec4<f32>(vertex.position, 1.0)
);
return out;
}
```
The new way where one needs to index into the array of `Mesh`es for the batch:
```rust
struct Vertex {
@builtin(instance_index) instance_index: u32,
@location(0) position: vec3<f32>,
};
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
out.clip_position = mesh_position_local_to_clip(
mesh[vertex.instance_index].model,
vec4<f32>(vertex.position, 1.0)
);
return out;
}
```
Note that using the instance_index is the default way to pass the per-object index into the shader, but if you wish to do custom rendering approaches you can pass it in however you like.
### [Reduce the size of MeshUniform to improve performance](https://github.com/bevyengine/bevy/pull/9416)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Rendering</div>
</div>
`Sphere::intersects_obb` and `Frustum::intersects_obb` now take an `Affine3A` instead of a `Mat4`. You can use `Affine3A::from_mat4` or `Transform::compute_affine` to get an `Affine3A`.
`MeshUniform` now stores its current and previous model transforms as 4x3 matrices. Helper functions were added to bevy_pbr::mesh_functions to unpack the data.
```rust
// 0.11
var model = mesh[instance_index].model;
// 0.12
#import bevy_pbr::mesh_functions::affine_to_square
var model = affine_to_square(mesh[instance_index].model);
```
### [Reorder render sets, refactor bevy_sprite to take advantage](https://github.com/bevyengine/bevy/pull/9236)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Rendering</div>
</div>
- Assets such as materials and meshes should now be created in `PrepareAssets` e.g. `prepare_assets<Mesh>`
- Queueing entities to `RenderPhase`s continues to be done in `Queue` e.g. `queue_sprites`
- Preparing resources (textures, buffers, etc.) should now be done in `PrepareResources`, e.g. `prepare_prepass_textures`, `prepare_mesh_uniforms`
- Prepare bind groups should now be done in `PrepareBindGroups` e.g. `prepare_mesh_bind_group`
- Any batching or instancing can now be done in `Prepare` where the order of the phase items is known e.g. `prepare_sprites`
### [Split `ComputedVisibility` into two components to allow for accurate change detection and speed up visibility propagation](https://github.com/bevyengine/bevy/pull/9497)
<div class="migration-guide-area-tags">
<div class="migration-guide-area-tag">Rendering</div>
</div>
The `ComputedVisibility` component has been split into `InheritedVisibility` and
`ViewVisibility`. Replace any usages of `ComputedVisibility::is_visible_in_hierarchy`
with `InheritedVisibility::get`, and replace `ComputedVisibility::is_visible_in_view`
with `ViewVisibility::get`.
```rust
// 0.11:
commands.spawn(VisibilityBundle {
visibility: Visibility::Inherited,
computed_visibility: ComputedVisibility::default(),
});
// 0.12:
commands.spawn(VisibilityBundle {
visibility: Visibility::Inherited,
inherited_visibility: InheritedVisibility::default(),
view_visibility: ViewVisibility::default(),
});
```
```rust
// 0.11:
fn my_system(q: Query<&ComputedVisibility>) {
for vis in &q {
if vis.is_visible_in_hierarchy() {
// 0.12:
fn my_system(q: Query<&InheritedVisibility>) {
for inherited_visibility in &q {
if inherited_visibility.get() {
```
```rust
// 0.11:
fn my_system(q: Query<&ComputedVisibility>) {
for vis in &q {
if vis.is_visible_in_view() {
// 0.12:
fn my_system(q: Query<&ViewVisibility>) {
for view_visibility in &q {
if view_visibility.get() {
```
```rust
// 0.11:
fn my_system(mut q: Query<&mut ComputedVisibility>) {
for vis in &mut q {