Skip to main content

BehaviorComponent

BehaviorComponent

ECS wrapper around a Behavior tree. Allows complex scripting behavior, including parallelization. Requires BehaviorSystem to be registered on EntityManager.

Kind: global class
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025

new exports.BehaviorComponent()

Example

new Entity()
.add(BehaviorComponent.from(
SequenceBehavior.from([
DelayBehavior.from(10),
DieBehavior.create(),
])
))
.build(ecd); // entity will self-destruct after 10 seconds

behaviorComponent.clock : ClockChannelType | number

What clock should be used for ticking associated behavior. Some behaviors need to run at the world's simulated time, while others will need to be executed in real-world time.

Kind: instance property of BehaviorComponent

behaviorComponent.flags : number

Kind: instance property of BehaviorComponent

behaviorComponent.behavior ⇒ Behavior | null

Kind: instance property of BehaviorComponent

behaviorComponent.behavior

Note that swapping behaviors during simulation may have unintended consequences

Kind: instance property of BehaviorComponent

ParamType
vBehavior

behaviorComponent.setFlag(flag) ⇒ void

Kind: instance method of BehaviorComponent

ParamType
flagnumber | BehaviorComponentFlag

behaviorComponent.clearFlag(flag) ⇒ void

Kind: instance method of BehaviorComponent

ParamType
flagnumber | BehaviorComponentFlag

behaviorComponent.writeFlag(flag, value)

Kind: instance method of BehaviorComponent

ParamType
flagnumber | BehaviorComponentFlag
valueboolean

behaviorComponent.getFlag(flag) ⇒ boolean

Kind: instance method of BehaviorComponent

ParamType
flagnumber | BehaviorComponentFlag

BehaviorComponent.fromOne

use from instead

Kind: static property of BehaviorComponent

BehaviorComponent.looping_function

use loop instead

Kind: static property of BehaviorComponent

BehaviorComponent.serializable : boolean

Kind: static property of BehaviorComponent
Read only: true

BehaviorComponent.typeName : string

Kind: static property of BehaviorComponent
Read only: true

BehaviorComponent.loop(action, [thisArg]) ⇒ BehaviorComponent

Executes input function every update cycle. Will run forever, or until function throws.

Kind: static method of BehaviorComponent

ParamTypeDescription
actionfunctionfunction to loop over
[thisArg]*

BehaviorComponent.from(b) ⇒ BehaviorComponent

Kind: static method of BehaviorComponent

ParamType
bBehavior