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