Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Dynamic Types

Dynamic type (dyntype for short) is a user-defined data structure that supports additional features which makes it available from the editor and serializable to the standard asset format. Dyntypes also supports handles to scene or ui nodes, and the engine will maintain their correctness automatically. Typical definition of a dyntype could be the following:

#![allow(unused)]
fn main() {
#[derive(Visit, Reflect, TypeUuidProvider, Clone, Default)]
#[type_uuid(id = "df479e17-1db1-449f-b91b-029d05332c9b")]
struct MyData {
    target_name: String,
    rigid_body: Handle<RigidBody>
}
}

Registration

Dyntypes must be registered in the engine to be serialiable, otherwise the engine will simply ignore them. This can be done like so:

#![allow(unused)]
fn main() {
impl Plugin for MyGame {
    fn register(&self, context: PluginRegistrationContext) -> GameResult {
        context.dyn_type_constructors.add::<MyData, Self>("My Data");
        Ok(())
    }
}
}

Hot-reloading

Dyntypes are also correctly handled during native code hot reloading; the engine will serialize their content first before the reload and then deserialize it back in the type instance after the reload is finished. This fact makes dyntypes safe in native code hot reloading.