diff --git a/release-content/0.14/release-notes/5781_bevy_reflect_Recursive_registration.md b/release-content/0.14/release-notes/5781_bevy_reflect_Recursive_registration.md index 1333ed77b7..8785b3652a 100644 --- a/release-content/0.14/release-notes/5781_bevy_reflect_Recursive_registration.md +++ b/release-content/0.14/release-notes/5781_bevy_reflect_Recursive_registration.md @@ -1 +1,39 @@ -TODO +Bevy uses [reflection](https://docs.rs/bevy_reflect/latest/bevy_reflect/) in order to dynamically process data for things like serialization and deserialization. +A Bevy app has a `TypeRegistry` to keep track of which types exist. +Users can register their custom types when initializing the app or plugin. + +```rust +#[derive(Reflect)] +struct Data { + value: T, +} + +#[derive(Reflect)] +struct Blob { + contents: Vec, +} + +app + .register_type::>() + .register_type::() + .register_type::>() +``` + +In the code above, `Data` depends on `Blob` which depends on `Vec`, +which means that all three types need to be manually registered— +even if we only care about `Data`. + +This is both tedious and error-prone, especially when these type dependencies are only +used in the context of other types (i.e. they aren't used as standalone types). + +In 0.14, any type that derives `Reflect` will automatically register all of its type dependencies. +So when we register `Data`, `Blob` will be registered as well (which will register `Vec`), +thus simplifying our registration down to a single line: + +```rust +app.register_type::>() +``` + +Note that removing the registration for `Data` now also means that `Blob` and `Vec` may +not be registered either, unless they were registered some other way. +If those types are needed as standalone types, they should be registered separately.