Skip to content

Commit 0508d6a

Browse files
alice-i-cecileChristopherBiscardi
authored andcommitted
Detailed migration guide for automatic reflection registration (#21109)
## Objective - The migration for automatic registration is non-trivial with default features off. - Fixes #21092. ## Solution - Carefully explain how this works and the steps users and libraries should take to migrate. - Link #15030 (auto-register), #20345 (registration removal) and #20893 (example of generic registration) to guide users who want to see this in action. --------- Co-authored-by: Chris Biscardi <[email protected]>
1 parent c8cb1e0 commit 0508d6a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Changes to type registration for reflection
3+
pull_requests: [15030, 20435, 20893]
4+
---
5+
6+
Calling `.register_type` has long been a nuisance for Bevy users: both library authors and end users.
7+
This step was previously required in order to register reflected type information in the `TypeRegistry`.
8+
9+
In Bevy 0.17 however, types which implement `Reflect` are now automatically registered, with the help of some compiler magic.
10+
You should be able to remove almost all of your `register_type` calls.
11+
This comes with a few caveats however:
12+
13+
1. Automatic type registration is gated by feature flags.
14+
2. There are two approaches to do this: one has incomplete platform support, while the other relies on a specific project structure.
15+
3. Generic types are not automatically registered, and must still be manually registered.
16+
17+
In order for Bevy to automatically register your types, you need to turn on the `reflect_auto_register` feature, or the fallback `reflect_auto_register_static`.
18+
The `reflect_auto_register` feature is part of Bevy's default features, and can be overridden by the `reflect_auto_register_static` feature flag.
19+
Be aware that the `reflect_auto_register_static` feature comes with some caveats for project structure: check the docs for [load_type_registrations!](https://docs.rs/bevy/0.17.0-rc.1/bevy/reflect/macro.load_type_registrations.html) and follow the [`auto_register_static` example](https://github.com/bevyengine/bevy/tree/main/examples/reflection/auto_register_static).
20+
21+
We recommend that you:
22+
23+
1. Enable `reflect_auto_register` in your application code, CI and in examples/tests. You can enable `bevy` features for tests only by adding a matching copy of `bevy` to `dev-dependencies` with the needed features enabled.
24+
2. Do not enable the `reflect_auto_register` feature or the fallback `reflect_auto_register_static` in your library code.
25+
3. As a library author, you can safely remove all non-generic `.register_type` calls.
26+
4. As a user, if you run into an unregistered generic type with the correct feature enabled, file a bug with the project that defined the offending type, and workaround it by calling `.register_type` manually.
27+
5. If you are on an unsupported platform but need reflection support, try the `reflect_autoregister_static` feature, and consider working upstream to add support for your platform in `inventory`. As a last resort, you can still manually register all of the needed types in your application code.

0 commit comments

Comments
 (0)