NEOLearn

The type registry

How reflected types are registered in AppTypeRegistry, what type data such as ReflectComponent and ReflectDefault adds, and how to reflect your own traits.

Updated October 20, 2026

On this page

Reflection works on values you already have. To go from a name to a type (when a file says "my_game::Stats") or to find out what a type can do (is it a component? does it have a default?), the engine looks the type up in the type registry. The app's registry is the AppTypeRegistry resource.

Registration#

In NEO's builds, every type that derives Reflect is registered automatically when the app starts (the reflect_auto_register feature, which is on). This works on every platform NEO builds for, including the web.

Generic types are the exception: register each concrete version you use.

Rust
app.register_type::<Inventory<Weapon>>()
    .register_type::<Inventory<Potion>>();

register_type is also how you register types when automatic registration is off.

Type data#

A registration holds the type's TypeInfo (its fields, variants and type path) and any number of type data values: small structs that let you use one of the type's traits without knowing the type. You add them in the derive:

Rust
#[derive(Component, Reflect, Default)]
#[reflect(Component, Default)]
struct Stats {
    health: u32,
}
Type dataAdded byWhat it lets you do
ReflectComponent#[reflect(Component)]Insert, read, apply, remove and copy the component on an entity from reflected data. Needed for the component to be saved in a world.
ReflectResource#[reflect(Resource)]The same for a resource. Needed for the resource to be saved in a world.
ReflectDefault#[reflect(Default)]Make a default value.
ReflectSerialize, ReflectDeserialize#[reflect(Serialize, Deserialize)]Use the type's own serde implementation when serializing.
ReflectFromReflectAutomaticBuild the concrete type from a dynamic value.
ReflectAsset#[reflect(Asset)]Load and store the type as an asset by reflection, as the RON loader does.

Add type data a derive didn't include, or for a type you don't own, with register_type_data:

Rust
use neo::reflect::{ReflectDeserialize, ReflectSerialize};

app.register_type_data::<Option<String>, ReflectSerialize>()
    .register_type_data::<Option<String>, ReflectDeserialize>();

Use the registry#

Rust
use neo::ecs::reflect::ReflectComponent;

fn print_stats(world: &mut World, entity: Entity) {
    let registry = world.resource::<AppTypeRegistry>().clone();
    let registry = registry.read();

    let Some(registration) = registry.get_with_short_type_path("Stats") else { return };
    let Some(reflect_component) = registration.data::<ReflectComponent>() else { return };

    if let Some(value) = reflect_component.reflect(world.entity(entity)) {
        info!("{value:?}");
    }
}
MethodReturns
get(type_id)The registration for a TypeId.
get_with_type_path("my_game::Stats")By full type path.
get_with_short_type_path("Stats")By short name, if it is unambiguous.
get_type_data::<D>(type_id)One kind of type data for a type.
iter()Every registration.

AppTypeRegistry is shared behind a lock: read() for lookups, write() to register. Don't hold a write lock while systems run that read it.

Reflect your own traits#

#[reflect_trait] on a trait generates a Reflect<Trait> type data. Register it for each type that implements the trait, and you can call the trait on a &dyn Reflect:

Rust
use neo::reflect::TypeRegistry;

#[reflect_trait]
trait Describe {
    fn describe(&self) -> String;
}

#[derive(Reflect)]
#[reflect(Describe)]
struct Door {
    locked: bool,
}

impl Describe for Door {
    fn describe(&self) -> String {
        if self.locked { "a locked door".into() } else { "a door".into() }
    }
}

fn describe_any(value: &dyn Reflect, registry: &TypeRegistry) -> Option<String> {
    let type_id = value.reflect_type_info().type_id();
    let describe = registry.get_type_data::<ReflectDescribe>(type_id)?;
    Some(describe.get(value)?.describe())
}

For type data with your own logic, implement CreateTypeData<T> for a struct and register it the same way. Example: cargo run --example type_data, from the engine core's workspace (the folder of the engine source that holds the neo crate's Cargo.toml).

Next steps#