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<Behavior, CnResult>
fn from_baked(bytes: &[u8]) -> Result<Behavior, 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.Source§impl<'de> Deserialize<'de> for Behavior
impl<'de> Deserialize<'de> for Behavior
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Behavior, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Behavior, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl RuntimeComponent for Behavior
Source§impl Serialize for Behavior
impl Serialize for Behavior
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Behavior
impl RefUnwindSafe for Behavior
impl Send for Behavior
impl Sync for Behavior
impl Unpin for Behavior
impl UnsafeUnpin for Behavior
impl UnwindSafe for Behavior
Blanket Implementations§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more