diff --git a/content/learn/book/migration-guides/0.8-0.9/_index.md b/content/learn/book/migration-guides/0.8-0.9/_index.md index f91812f9e3..1dd17fa478 100644 --- a/content/learn/book/migration-guides/0.8-0.9/_index.md +++ b/content/learn/book/migration-guides/0.8-0.9/_index.md @@ -177,6 +177,7 @@ commands.entity(some_entity).remove_bundle::(); // New (0.9) commands.entity(some_entity).remove::(); ``` + Replace `remove_bundle_intersection` with `remove_intersection`: ```rust @@ -624,45 +625,88 @@ After: ); ``` -### [Replace root list with struct](https://github.com/bevyengine/bevy/pull/6354) +### Scene serialization format improvements from [#6354](https://github.com/bevyengine/bevy/pull/6354), [#6345](https://github.com/bevyengine/bevy/pull/6345), and [#5723](https://github.com/bevyengine/bevy/pull/5723) -The scene file format now uses a struct as the root object rather than a list of entities. The list of entities is now found in the `entities` field of this struct. +* The root of the scene is now a struct rather than a list +* Components are now a map keyed by type name rather than a list +* Type information is now omitted when possible, making scenes much more compact -```rust +Scenes serialized with Bevy 0.8 will need to be recreated, but it is possible to hand-edit scenes to match the new format. + +Here's an example scene in the old and new format: + +```javascript // Old (Bevy 0.8) [ ( entity: 0, components: [ - // Components... - ] + { + "type": "bevy_transform::components::transform::Transform", + "struct": { + "translation": { + "type": "glam::vec3::Vec3", + "value": (0.0, 0.0, 0.0), + }, + "rotation": { + "type": "glam::quat::Quat", + "value": (0.0, 0.0, 0.0, 1.0), + }, + "scale": { + "type": "glam::vec3::Vec3", + "value": (1.0, 1.0, 1.0), + }, + }, + }, + { + "type": "scene::ComponentB", + "struct": { + "value": { + "type": "alloc::string::String", + "value": "hello", + }, + }, + }, + { + "type": "scene::ComponentA", + "struct": { + "x": { + "type": "f32", + "value": 1.0, + }, + "y": { + "type": "f32", + "value": 2.0, + }, + }, + }, + ], + ), + ( + entity: 1, + components: [ + { + "type": "scene::ComponentA", + "struct": { + "x": { + "type": "f32", + "value": 3.0, + }, + "y": { + "type": "f32", + "value": 4.0, + }, + }, + }, + ], ), ] // New (Bevy 0.9) ( - entities: [ - ( - entity: 0, - components: [ - // Components... - ] - ), - ] -) -``` - -### [Use map for scene `components`](https://github.com/bevyengine/bevy/pull/6345) - -The scene format now uses a map to represent the collection of components. Scene files will need to update from the old list format. - -```rust -// Old (Bevy 0.8) -[ - ( - entity: 0, - components: [ - { + entities: { + 0: ( + components: { "bevy_transform::components::transform::Transform": ( translation: ( x: 0.0, @@ -676,48 +720,25 @@ The scene format now uses a map to represent the collection of components. Scene z: 1.0 ), ), - }, - { - "my_crate::Foo": ( - text: "Hello World", + "scene::ComponentB": ( + value: "hello", ), - }, - { - "my_crate::Bar": ( - baz: 123, + "scene::ComponentA": ( + x: 1.0, + y: 2.0, ), }, - ], - ), -] - -// New (Bevy 0.9) -[ - ( - entity: 0, - components: { - "bevy_transform::components::transform::Transform": ( - translation: ( - x: 0.0, - y: 0.0, - z: 0.0 - ), - rotation: (0.0, 0.0, 0.0, 1.0), - scale: ( - x: 1.0, - y: 1.0, - z: 1.0 + ), + 1: ( + components: { + "scene::ComponentA": ( + x: 3.0, + y: 4.0, ), - ), - "my_crate::Foo": ( - text: "Hello World", - ), - "my_crate::Bar": ( - baz: 123 - ), - }, - ), -] + }, + ), + } +) ``` ### [Derive `Reflect` + `FromReflect` for input types](https://github.com/bevyengine/bevy/pull/6232) @@ -725,40 +746,6 @@ The scene format now uses a map to represent the collection of components. Scene * `Input` now implements `Reflect` via `#[reflect]` instead of `#[reflect_value]`. This means it now exposes its private fields via the `Reflect` trait rather than being treated as a value type. For code that relies on the `Input` struct being treated as a value type by reflection, it is still possible to wrap the `Input` type with a wrapper struct and apply `#[reflect_value]` to it. * As a reminder, private fields exposed via reflection are not subject to any stability guarantees. -### [Improve serialization format even more](https://github.com/bevyengine/bevy/pull/5723) - -This PR reduces the verbosity of the scene format. Scenes will need to be updated accordingly: - -```js -// Old format -{ - "type": "my_game::item::Item", - "struct": { - "id": { - "type": "alloc::string::String", - "value": "bevycraft:stone", - }, - "tags": { - "type": "alloc::vec::Vec", - "list": [ - { - "type": "alloc::string::String", - "value": "material" - }, - ], - }, - } -} - -// New format -{ - "my_game::item::Item": ( - id: "bevycraft:stone", - tags: ["material"] - ) -} -``` - ### [Relax bounds on `Option`](https://github.com/bevyengine/bevy/pull/5658) If using `Option` with Bevy’s reflection API, `T` now needs to implement `FromReflect` rather than just `Clone`. This can be achieved easily by simply deriving `FromReflect`: