Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - 0.8 Migration guide #389

Closed
wants to merge 51 commits into from
Closed
Changes from 4 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a1e2164
create guide
IceSentry Jun 29, 2022
02a8de7
first draft of all the PRs tagged as breaking change
IceSentry Jun 29, 2022
4d51cfe
apply some suggestions
IceSentry Jun 29, 2022
c506e6c
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
ccfff67
update CameraUi
IceSentry Jul 15, 2022
586daf4
add global task pool section
IceSentry Jul 15, 2022
81d4b6e
update migration guide
IceSentry Jul 15, 2022
fe3970c
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
e62e2bf
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
fd517ea
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
0c22c52
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
f0039f9
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
a14a65c
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
d1084fe
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
43be735
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
92c47b7
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 15, 2022
8fce721
add code blocks and move camera rendering section
IceSentry Jul 22, 2022
5f3016c
update guide
IceSentry Jul 22, 2022
463223c
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
bba25a2
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
a7767e1
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
c3a78d1
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
83ad9aa
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
b55d010
address more feedback
IceSentry Jul 22, 2022
6c6e7d7
spatial bundle
IceSentry Jul 22, 2022
a4b7c28
add more breaking PRs
IceSentry Jul 22, 2022
9bd7ceb
fix TODOs
IceSentry Jul 22, 2022
32f7a67
reorder by importance
IceSentry Jul 22, 2022
9f3770d
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
46683e4
move SpatialBundle closer to visibility stuff
IceSentry Jul 22, 2022
20aaf38
rephrase
IceSentry Jul 22, 2022
9e564eb
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
f5c5162
merge with other section
IceSentry Jul 22, 2022
18ccaa1
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
01631ff
add small sentence
IceSentry Jul 22, 2022
5152536
Merge remote-tracking branch 'origin/0.8-migration-guide' into 0.8-mi…
IceSentry Jul 22, 2022
5a739fe
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
8bbdd61
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
492c8a2
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 22, 2022
9d70e9a
Apply suggestions from code review
IceSentry Jul 22, 2022
5456165
update 16-bit
IceSentry Jul 22, 2022
bfcc0e2
UiCameraConfig
IceSentry Jul 23, 2022
2b40789
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 23, 2022
eb26d69
Apply suggestions from code review
IceSentry Jul 23, 2022
4072013
various fixes
IceSentry Jul 23, 2022
ec757aa
update reflect_partial_eq
IceSentry Jul 23, 2022
754f295
Add no default features from PR #5447
aevyrie Jul 26, 2022
7e681e9
Merge pull request #4 from aevyrie/patch-1
IceSentry Jul 26, 2022
de8f981
show thread_pool origin
IceSentry Jul 26, 2022
c739af9
Update content/learn/book/migration-guides/0.7-0.8/_index.md
IceSentry Jul 26, 2022
73a5529
ShaderType
cart Jul 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 302 additions & 0 deletions content/learn/book/migration-guides/0.7-0.8/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
+++
title = "0.7 to 0.8"
weight = 4
sort_by = "weight"
template = "book-section.html"
page_template = "book-section.html"
insert_anchor_links = "right"
[extra]
long_title = "Migration Guide: 0.7 to 0.8"
+++

<!-- Github filter used to find the relevant PRs "is:pr label:C-Breaking-Change closed:>2022-04-15 [Merged by Bors]" -->

### [Make ScalingMode more flexible](https://github.com/bevyengine/bevy/pull/3253)

Adds ability to specify scaling factor for `WindowSize`, size of the fixed axis for `FixedVertical` and `FixedHorizontal` and a new `ScalingMode` that is a mix of `FixedVertical` and `FixedHorizontal`

### [Allow closing windows at runtime](https://github.com/bevyengine/bevy/pull/3575)

`bevy::input::system::exit_on_esc_system` has been removed. Use `bevy::window::close_on_esc` instead.
`CloseWindow` has been removed. Use `Window::close` instead.
The Close variant has been added to `WindowCommand`. Handle this by closing the relevant window.

### [Make RunOnce a non-manual System impl](https://github.com/bevyengine/bevy/pull/3922)

The run criterion `RunOnce`, which would make the controlled systems run only once, has been replaced with a new run criterion function ShouldRun::once. Replace all instances of RunOnce with `ShouldRun::once`.

### [Move system_param fetch struct into anonymous scope to avoid name collisions](https://github.com/bevyengine/bevy/pull/4100)

For code that was using a system param's fetch struct, such as EventReader's EventReaderState, the fetch struct can now be identified via the SystemParam trait associated type Fetch, e.g. for `EventReader<T>` it can be identified as `<EventReader<'static, 'static, T>` as SystemParam>::Fetch
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Task doesn't impl Component](https://github.com/bevyengine/bevy/pull/4113)

If you need a `Task` to be a `Component` you should use a wrapper type.

```rs
// 0.7
fn system(mut commands: Commands) {
let task = thread_pool.spawn(async move {
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
let start_time = Instant::now();
while Instant::now() - start_time < Duration::from_secs_f32(5.0) {
// Spinning for 'duration', simulating doing hard
}
Vec2::ZERO
});
commands.spawn().insert(task);
}

// 0.8
#[derive(Component)]
struct ComputeVec2(Task<Vec2>);

fn system(mut commands: Commands) {
let task = thread_pool.spawn(async move {
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
let start_time = Instant::now();
while Instant::now() - start_time < Duration::from_secs_f32(5.0) {
// Spinning for 'duration', simulating doing hard
}
Vec2::ZERO
});
commands.spawn().insert(ComputeVec2(task))
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
}
```

### [Split time functionality into bevy_time](https://github.com/bevyengine/bevy/pull/4187)

* Time related types (e.g. `Time`, `Timer`, `Stopwatch`, `FixedTimestep`, etc.) should be imported from `bevy::time::*` rather than `bevy::core::*`.
* If you were adding `CorePlugin` manually, you'll also want to add `TimePlugin` from `bevy::time`.
* The `bevy::core::CorePlugin::Time` system label is replaced with `bevy::time::TimeSystem`.

### [Move float_ord from bevy_core to bevy_utils](https://github.com/bevyengine/bevy/pull/4189)

Replace imports of `bevy::core::FloatOrd` with `bevy::utils::FloatOrd`.

### [Move Rect to bevy_ui and rename it to UiRect](https://github.com/bevyengine/bevy/pull/4276)

The `Rect` type got renamed to `UiRect`. To migrate you just have to change every occurrence of `Rect` to `UiRect`.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Rename ElementState to ButtonState](https://github.com/bevyengine/bevy/pull/4314)

The `ElementState` type received a rename and is now called `ButtonState`. To migrate you just have to change every occurrence of `ElementState` to `ButtonState`.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Improve docs and naming for RawWindowHandle functionality](https://github.com/bevyengine/bevy/pull/4335)

rename `HasRawWindowHandleWrapper` to `ThreadLockedRawWindowHandleWrapper`
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Migrate to encase from crevice](https://github.com/bevyengine/bevy/pull/4339)
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

cart marked this conversation as resolved.
Show resolved Hide resolved
#### StorageBuffer

* removed set_body(), values(), values_mut(), clear(), push(), append()
* added set(), get(), get_mut()

#### UniformVec -> UniformBuffer

* renamed uniform_buffer() to buffer()
* removed len(), is_empty(), capacity(), push(), reserve(), clear(), values()
* added set(), get()

#### DynamicUniformVec -> DynamicUniformBuffer

* renamed uniform_buffer() to buffer()
* removed capacity(), reserve()

### [Make paused timers update just_finished on tick](https://github.com/bevyengine/bevy/pull/4445)

`Timer::times_finished has` been renamed to `Timer::times_finished_this_tick` for clarity.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Change default Image FilterMode to Linear](https://github.com/bevyengine/bevy/pull/4465)

```rs
// 0.7

//TODO

// 0.8

// TODO
```

### [Remove .system()](https://github.com/bevyengine/bevy/pull/4499)

You can no longer use `.system()`. It was deprecated in 0.7.0. You can just remove the method call.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

If you needed this for tests purposes, you can use `bevy_ecs::system::assert_is_system` instead.

### [Change gamepad.rs tuples to normal structs](https://github.com/bevyengine/bevy/pull/4519)

The `Gamepad`, `GamepadButton`, `GamepadAxis`, `GamepadEvent` and `GamepadEventRaw` types are now normal structs instead of tuple structs and have a new() function. To migrate change every instantiation to use the `new()` function instead and use the appropriate field names instead of .0 and .1.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Remove EntityMut::get_unchecked](https://github.com/bevyengine/bevy/pull/4547)

Replace calls to `EntityMut::get_unchecked` with calls to `EntityMut::get`.

### [Replace ReadOnlyFetch with ReadOnlyWorldQuery](https://github.com/bevyengine/bevy/pull/4626)

The trait ReadOnlyFetch has been replaced with ReadOnlyWorldQuery along with the WorldQueryGats::ReadOnlyFetch assoc type which has been replaced with <WorldQuery::ReadOnly as WorldQueryGats>::Fetch
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

The trait `ReadOnlyFetch` has been replaced with `ReadOnlyWorldQuery` along with the `WorldQueryGats::ReadOnlyFetch` assoc type which has been replaced with `<WorldQuery::ReadOnly as WorldQueryGats>::Fetch`

* Any where clauses such as `QueryFetch<Q>: ReadOnlyFetch` should be replaced with `Q: ReadOnlyWorldQuery`.
* Any custom world query impls should implement `ReadOnlyWorldQuery` insead of `ReadOnlyFetch`
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

Functions `update_component_access` and `update_archetype_component_access` have been moved from the `FetchState` trait to `WorldQuery`

* Any callers should now call `Q::update_component_access(state` instead of `state.update_component_access` (and `update_archetype_component_access` respectively)
* Any custom world query impls should move the functions from the `FetchState` impl to `WorldQuery` impl

`WorldQuery` has been made an `unsafe trait`, `FetchState` has been made a safe `trait`. (I think this is how it should have always been, but regardless this is _definitely_ necessary now that the two functions have been moved to `WorldQuery`)

* If you have a custom `FetchState` impl make it a normal `impl` instead of `unsafe impl`
* If you have a custom `WorldQuery` impl make it an `unsafe impl`, if your code was sound before it is going to still be sound

### [Fix unsoundness with Or/AnyOf/Option component access'](https://github.com/bevyengine/bevy/pull/4659)

<!-- TODO make this a bit friendlier -->

If you are now getting query conflicts from `Or`/`AnyOf`/`Option` rip to you and ur welcome for it now being caught.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Remove task_pool parameter from par_for_each(_mut)](https://github.com/bevyengine/bevy/pull/4705)

The `task_pool` parameter for `Query(State)::par_for_each(_mut)` has been removed. Remove these parameters from all calls to these functions.

Before:

```rust
fn parallel_system(
task_pool: Res<ComputeTaskPool>,
query: Query<&MyComponent>,
) {
query.par_for_each(&task_pool, 32, |comp| {
...
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
});
}
```

After:

```rust
fn parallel_system(query: Query<&MyComponent>) {
query.par_for_each(32, |comp| {
...
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
});
}
```

If using `Query(State)` outside of a system run by the scheduler, you may need to manually configure and initialize a `ComputeTaskPool` as a resource in the `World`.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Fail to compile on 16-bit platforms](https://github.com/bevyengine/bevy/pull/4736)

`bevy_ecs` will now explicitly fail to compile on 16-bit platforms. If this is required, there is currently no alternative. Please file an issue (<https://github.com/bevyengine/bevy/issues>) to help detail your use case.
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Camera Driven Rendering](https://github.com/bevyengine/bevy/pull/4745)

<!-- TODO pls cart add a migration guide section :( -->

This is a very complicated change and it is recommended to read the linked PRs for more details

```rust
// old 3d perspective camera
commands.spawn_bundle(PerspectiveCameraBundle::default())

// new 3d perspective camera
commands.spawn_bundle(Camera3dBundle::default())
```

```rust
// old 2d orthographic camera
commands.spawn_bundle(OrthographicCameraBundle::new_2d())

// new 2d orthographic camera
commands.spawn_bundle(Camera2dBundle::default())
```

```rust
// old 3d orthographic camera
commands.spawn_bundle(OrthographicCameraBundle::new_3d())

// new 3d orthographic camera
commands.spawn_bundle(Camera3dBundle {
projection: OrthographicProjection {
scale: 3.0,
scaling_mode: ScalingMode::FixedVertical,
..default()
}.into(),
..default()
})
```

UI no longer requires a dedicated camera. `UiCameraBundle` has been removed. `Camera2dBundle` and `Camera3dBundle` now both default to rendering UI as part of their own render graphs. To disable UI rendering for a camera, disable it using the CameraUi component:

```rust
commands
.spawn_bundle(Camera3dBundle::default())
.insert(CameraUi {
is_enabled: false,
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
..default()
})
```
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Enforce type safe usage of Handle::get](https://github.com/bevyengine/bevy/pull/4794)

`Assets::<T>::get` and `Assets::<T>::get_mut` now require that the passed handles are `Handle<T>`, improving the type safety of handles. If you were previously passing in:

* a `HandleId`, use `&Handle::weak(id)` instead, to create a weak handle. You may have been able to store a type safe `Handle` instead.
* a `HandleUntyped`, use `&handle_untyped.typed_weak()` to create a weak handle of the specified type. This is most likely to be the useful when using [load_folder](https://docs.rs/bevy_asset/latest/bevy_asset/struct.AssetServer.html#method.load_folder)
* a `Handle<U>` of of a different type, consider whether this is the correct handle type to store. If it is (i.e. the same handle id is used for multiple different Asset types) use `Handle::weak(handle.id)` to cast to a different type.

### [Allow higher order systems](https://github.com/bevyengine/bevy/pull/4833)
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

<!-- TODO marked as breaking change, but need to figure out what actually is breaking -->
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

### [Added offset parameter to TextureAtlas::from_grid_with_padding](https://github.com/bevyengine/bevy/pull/4836)

Calls to `TextureAtlas::from_grid_with_padding` should be modified to include a new parameter, which can be set to `Vec2::ZERO` to retain old behaviour.

```rust
from_grid_with_padding(texture, tile_size, columns, rows, padding)
|
V
from_grid_with_padding(texture, tile_size, columns, rows, padding, Vec2::ZERO)
IceSentry marked this conversation as resolved.
Show resolved Hide resolved
```

### [Split mesh shader files](https://github.com/bevyengine/bevy/pull/4867)

* In shaders for 3D meshes:
* `#import bevy_pbr::mesh_view_bind_group` -> `#import bevy_pbr::mesh_view_bindings`
* `#import bevy_pbr::mesh_struct` -> `#import bevy_pbr::mesh_types`
* NOTE: If you are using the mesh bind group at bind group index 2, you can remove those binding statements in your shader and just use `#import bevy_pbr::mesh_bindings` which itself imports the mesh types needed for the bindings.
* In shaders for 2D meshes:
* `#import bevy_sprite::mesh2d_view_bind_group` -> `#import bevy_sprite::mesh2d_view_bindings`
* `#import bevy_sprite::mesh2d_struct` -> `#import bevy_sprite::mesh2d_types`
* NOTE: If you are using the mesh2d bind group at bind group index 2, you can remove those binding statements in your shader and just use `#import bevy_sprite::mesh2d_bindings` which itself imports the mesh2d types needed for the bindings.

### [Camera Driven Viewports](https://github.com/bevyengine/bevy/pull/4898)

`Camera::projection_matrix` is no longer a public field. Use the new `Camera::projection_matrix()` method instead:

```rust

// 0.7
let projection = camera.projection_matrix;
IceSentry marked this conversation as resolved.
Show resolved Hide resolved

// 0.8
let projection = camera.projection_matrix();
```

### [diagnostics: meaningful error when graph node has wrong number of inputs](https://github.com/bevyengine/bevy/pull/4924)

Exhaustive matches on `RenderGraphRunnerError` will need to add a branch to handle the new `MismatchedInputCount` variant.

### [Make Reflect safe to implement](https://github.com/bevyengine/bevy/pull/5010)

* Reflect derives should not have to change anything
* Manual reflect impls will need to remove the `unsafe` keyword, add `any()` implementations, and rename the old `any` and `any_mut` to `as_any` and `as_mut_any`.
* Calls to `any`/`any_mut` must be changed to `as_any`/`as_mut_any`

### [Mark mutable APIs under ECS storage as pub(crate)](https://github.com/bevyengine/bevy/pull/5065)

<!-- Dear God, I hope not. -->

If you experienced any problems caused by this change, please [create an issue](https://github.com/bevyengine/bevy/issues) explaining _in detail_ what you were doing with those apis.