pub struct Behavior {
pub asset_id: AssetId,
pub on: BehaviorSource,
pub scope: Vec<String>,
pub locals: Vec<BehaviorLocal>,
pub queries: Vec<BehaviorQuery>,
pub body: Vec<BehaviorNode>,
pub once: bool,
pub delay: f32,
pub cooldown: f32,
}Expand description
A unit of world logic: an event source, the entities it runs against, its state, the world it reads, and the nodes it runs.
A behavior with an empty scope runs once per firing, world-scoped. A
behavior with a scope runs once per matching entity, each with its own
copy of locals, and "self" resolves to that entity.
locals and queries are declared here and resolved to dense slots once,
when the world starts, so nothing is looked up by name while it runs. A
query naming an unknown component is a build error.
once limits a behavior to a single firing; cooldown enforces a minimum
number of seconds between firings; delay postpones the nodes after the
firing decision, which is made at fire time rather than after the delay.
Timers, delays, and cooldowns freeze while a menu is open, like the rest of
the world clock.
Fields§
§asset_id: AssetIdAsset identity; injected via inject_name. Not part of args.
on: BehaviorSourceThe event that fires this behavior.
scope: Vec<String>Component names selecting the entities this behavior runs against. An
empty list runs it once, world-scoped, with no "self".
The names are matched against the components entities carry while the
world runs, which are not always the ones a world declares: the build
expands some types away, compiles others into the resource stream, and a
load-time pass decomposes the rest. "Prop" is the common case and
works, resolving to the marker decomposition leaves on every prop’s
entity, model- and mesh-backed alike. A name with no runtime counterpart
is a build error rather than a scope that silently matches nothing.
locals: Vec<BehaviorLocal>Per-entity state. Each matching entity gets its own copy, reset to the declared value when the world starts. Locals are never persisted.
queries: Vec<BehaviorQuery>World reads, resolved once per tick into a stable-ordered entity list.
body: Vec<BehaviorNode>The nodes run, in order, each time the behavior fires.
once: boolFire at most once per run.
delay: f32Seconds between the firing decision and the nodes running (0 runs
them immediately).
cooldown: f32Minimum seconds between firings (0 allows every firing).
Implementations§
Source§impl Behavior
impl Behavior
Sourcepub fn plays_sound(&self) -> bool
pub fn plays_sound(&self) -> bool
Whether any node plays an audio clip, so the runtime knows this behavior needs the audio system and its clip payloads cached.
Sourcepub fn saves_state(&self) -> bool
pub fn saves_state(&self) -> bool
Whether any node saves the world’s logic state, so the runtime knows to restore persisted state when the world starts.
Trait Implementations§
Source§impl Component for Behavior
impl Component for Behavior
Source§fn inject_name(&mut self, id: AssetId)
fn inject_name(&mut self, id: AssetId)
Source§fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>
Source§fn inject_locator(&mut self, _locator: PayloadLocator)
fn inject_locator(&mut self, _locator: PayloadLocator)
Source§impl ComponentSlot for Behavior
impl ComponentSlot for Behavior
Source§const DISCRIMINANT: u8
const DISCRIMINANT: u8
ComponentId.