Skip to main content

Component

Derive Macro Component 

Source
#[derive(Component)]
{
    // Attributes available to this derive:
    #[component]
}
Expand description

A derive macro that implements the khora_data::ecs::Component trait and generates a serializable mirror struct with From conversions.

For a component like:

#[derive(Component)]
pub struct Camera {
    pub projection: ProjectionType,
    pub aspect_ratio: f32,
}

This macro generates:

  • impl Component for Camera
  • pub struct SerializableCamera { ... } with Encode, Decode
  • impl From<Camera> for SerializableCamera
  • impl From<SerializableCamera> for Camera

Use #[component(skip)] on fields that should not be serialized (e.g., GPU handles). Those fields are filled with Default::default() when deserializing back.