Variant
Back to ScriptsWhy 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
Variantfor custom structs/enums used in#[State]. - Derive
Variantfor custom typed params/returns used inmethods!. - If type at boundary lacks Variant conversion, script compile fails.
- Variant drives how
script_varsvalues 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.
