Skip to main content

Behavior

Struct Behavior 

Source
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: AssetId

Asset identity; injected via inject_name. Not part of args.

§on: BehaviorSource

The 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: bool

Fire at most once per run.

§delay: f32

Seconds between the firing decision and the nodes running (0 runs them immediately).

§cooldown: f32

Minimum seconds between firings (0 allows every firing).

Implementations§

Source§

impl Behavior

Source

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.

Source

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.

Source

pub fn is_scoped(&self) -> bool

Whether the behavior runs against individual entities rather than the world as a whole.

Trait Implementations§

Source§

impl Clone for Behavior

Source§

fn clone(&self) -> Behavior

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for Behavior

Source§

const NAME: &'static str = "Behavior"

The registry name a world authors this component under.
Source§

fn inject_name(&mut self, id: AssetId)

Called after construction to inject the asset’s identity from the blob def. Only meaningful for components that look themselves up by id at runtime. The default implementation does nothing.
Source§

fn from_baked(bytes: &[u8]) -> Result<Self, CnResult>

Reconstruct this component from a blob record, whose bytes are the serialized runtime component (cook already ran the asset -> component translation). The default rejects: runtime-only components are never stored in a blob, so only loadable types provide an implementation.
Source§

fn inject_locator(&mut self, _locator: PayloadLocator)

Called after construction to inject the payload locator from the blob def. Only meaningful for components with a compiled payload. The default implementation does nothing (correct for most components).
Source§

impl ComponentSlot for Behavior

Source§

const DISCRIMINANT: u8

The component type’s stable id, used as its ComponentId.
Source§

fn slot(s: &ComponentStorage) -> &Column<Self>

Borrow this type’s column out of the storage.
Source§

fn slot_mut(s: &mut ComponentStorage) -> &mut Column<Self>

Mutably borrow this type’s column out of the storage.
Source§

impl Debug for Behavior

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Behavior

Source§

fn default() -> Behavior

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Behavior

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Behavior> for ComponentAsset

Source§

fn from(c: Behavior) -> Self

Converts to this type from the input type.
Source§

impl RuntimeComponent for Behavior

Source§

impl Serialize for Behavior

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.