1.5 KiB
1.5 KiB
Automatic registration example for platforms without inventory support
This example illustrates how to use automatic type registration of bevy_reflect
on platforms that don't support inventory
.
To run the example, use the provided Makefile
with make run
or run manually by setting env var and enabling the required feature:
BEVY_REFLECT_AUTO_REGISTER_STATIC=1 cargo run --features bevy/reflect_auto_register_static
This approach should generally work on all platforms, however it is less convenient and slows down linking. It's recommended to use it only as a fallback.
Here's a list of caveats of this approach:
load_type_registrations!
macro must be called before constructingApp
or usingTypeRegistry::register_derived_types
.- All of the types to be automatically registered must be declared in a separate from
load_type_registrations!
crate. This is why this example uses separatelib
andbin
setup. - Registration function names are cached in
target/type_registrations
. Due to incremental compilation the only way to rebuild this cache is to build withbevy/reflect_auto_register_static
(orauto_register_static
if just usingbevy_reflect
) feature disabled, then deletetarget/type_registrations
and rebuild again with this feature enabled andBEVY_REFLECT_AUTO_REGISTER_STATIC=1
environment variable set. Runningcargo clean
before recompiling is also an option, but it is even slower to do.
If you're experiencing linking issues try running cargo clean
before rebuilding.