Path: blob/main/release-content/release-notes/reflect_auto_registration.md
6592 views
---
---
Automatic Reflect
registration
Deriving Reflect
on types opts into Bevy's runtime reflection infrastructure, which is used to power systems like component runtime inspection and serialization. Before Bevy 0.17, any top-level types that derive Reflect
(not used as a field in some other Reflect
-ed type) had to be manually registered using register_type
for the runtime reflection to work with them. With this release, all types that [#[derive(Reflect)]
] are now automatically registered! This works for any types without generic type parameters and should reduce the boilerplate needed when adding functionality that depends on Reflect
.
In cases where automatic registration is undesirable, it can be opted-out of by adding #[reflect(no_auto_register)] reflect attribute to a type:
Unsupported platforms
This feature relies on the inventory
crate to collect all type registrations at compile-time. However, some niche platforms are not supported by inventory
, and while it would be best for any unsupported platforms to be supported upstream, sometimes it might not be possible. For this reason, there is a different implementation of this feature that works on all platforms. It comes with some caveats with regards to project structure and might increase compile time, so it is better used as a backup solution. The detailed instructions on how to use this feature can be found in this example
. Types can also still be manually registered using app.register_type::<T>()
.