Path: blob/main/examples/reflection/auto_register_static/src/lib.rs
9341 views
//! Demonstrates how to set up automatic reflect types registration for platforms without `inventory` support1use bevy::prelude::*;23// The type that should be automatically registered.4// All types subject to automatic registration must not be defined in the same crate as `load_type_registrations!``.5// Any `#[derive(Reflect)]` types within the `bin` crate are not guaranteed to be registered automatically.6#[derive(Reflect)]7struct Struct {8a: i32,9}1011mod private {12mod very_private {13use bevy::prelude::*;1415// Works with private types too!16#[allow(17clippy::allow_attributes,18dead_code,19reason = "This struct is used as a compilation test to test the derive macros, and as such is intentionally never constructed."20)]21#[derive(Reflect)]22struct PrivateStruct {23a: i32,24}25}26}2728/// This is the main entrypoint, bin just forwards to it.29pub fn main() {30App::new()31.add_plugins(DefaultPlugins)32.add_systems(Startup, startup)33.run();34}3536fn startup(reg: Res<AppTypeRegistry>) {37let registry = reg.read();38info!(39"Is `Struct` registered? {}",40registry.contains(core::any::TypeId::of::<Struct>())41);42info!(43"Type info of `PrivateStruct`: {:?}",44registry45.get_with_short_type_path("PrivateStruct")46.expect("Not registered")47);48}495051