Why Variant exists

Variant is runtime boundary type for script-state storage and dynamic method dispatch. It allows scene serialization, runtime call params, and script var transport between systems with stable conversion rules.

Rules

  • Derive Variant for custom structs/enums used in #[State].
  • Derive Variant for custom typed params/returns used in methods!.
  • If type at boundary lacks Variant conversion, script compile fails.
  • Variant drives how script_vars values deserialize from scene data.

Example

use perro_api::prelude::*; #[derive(Clone, Copy, Variant)]struct OrbitGoal { axis: Vector3 } #[derive(Clone, Copy, Variant)]enum Team { Player, Enemy } #[State]struct SpinnerState {    #[default = OrbitGoal { axis: Vector3::new(0.0, 1.0, 0.0) }]    orbit_goal: OrbitGoal,     #[default = Team::Player]    team: Team,}

Where Variant shows up

These pages cover where Variant conversion applies in daily script work.