Moosebrain
Based on game build 722832 | Last updated: 2026-04-22
Overview
MooseBrain is a behavior tree brain that controls the AI for the Moose entity. It manages priority-based behaviors including combat engagement, egg-laying mechanics, territorial leashing, and player-facing interactions. The brain uses a PriorityNode structure where higher-priority behaviors interrupt lower ones.
Usage example
local inst = SpawnPrefab("moose")
local brain = require("brains/moosebrain")
RunBrain(inst, brain)
-- Brain automatically handles:
-- - Combat via ChaseAndAttack
-- - Egg laying when WantsToLayEgg is true
-- - Leashing to landpoint location
-- - Facing nearby players
Dependencies & tags
External dependencies:
behaviours/faceentity-- provides FaceEntity behavior node for player-facingbehaviours/chaseandattack-- provides ChaseAndAttack behavior node for combatbehaviours/leash-- provides Leash behavior node for territorial bounds
Components used:
combat-- checkstargetproperty to determine if engaged in combatentitytracker-- callsGetEntity("egg")to check for existing egg entityknownlocations-- callsGetLocation("landpoint")for leash bounds andRememberLocation("spawnpoint")for spawn tracking
Tags:
notarget-- checked on target entities to exclude from facing behaviorbusy-- state tag checked to prevent facing during busy animations
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
bt | BehaviorTree | nil | Reference to the behavior tree instance created in OnStart(). |
Main functions
OnStart()
- Description: Initializes the behavior tree with priority-ordered behavior nodes. Sets up combat, egg-laying, leashing, facing, and wandering behaviors. Higher priority nodes interrupt lower ones.
- Parameters: None
- Returns: None
- Error states: Errors if
self.instis nil when accessing components or calling behavior functions. Errors ifknownlocationscomponent is missing when callingGetLocation().
OnInitializationComplete()
- Description: Records the entity's spawn position to the knownlocations component under the "spawnpoint" key. Called when brain initialization finishes.
- Parameters: None
- Returns: None
- Error states: Errors if
self.instis nil or ifknownlocationscomponent is not present on the entity.
GoHome(inst) (local)
- Description: Returns a BufferedAction for the GOHOME action if the entity should go away and has no combat target. Used by the WhileNode in the behavior tree.
- Parameters:
inst-- the entity instance - Returns: BufferedAction instance or
nilif conditions not met - Error states: None
GetFaceTargetFn(inst) (local)
- Description: Finds the closest player within START_FACE_DIST that does not have the "notarget" tag and when the entity is not in a busy state. Used by FaceEntity behavior.
- Parameters:
inst-- the entity instance - Returns: Player entity instance or
nilif no valid target found - Error states: None
KeepFaceTargetFn(inst, target) (local)
- Description: Validates whether the entity should continue facing a target. Returns false if entity is busy, has notarget tag, or is beyond KEEP_FACE_DIST from target.
- Parameters:
inst-- the entity instancetarget-- the target entity being faced
- Returns: boolean -- true if should keep facing, false otherwise
- Error states: None
LayEgg(inst) (local)
- Description: Returns a BufferedAction for the LAYEGG action if the entity wants to lay an egg and no egg entity is currently tracked. Used by DoAction in the behavior tree.
- Parameters:
inst-- the entity instance - Returns: BufferedAction instance or
nilif conditions not met - Error states: None
Events & listeners
- Listens to: None identified
- Pushes: None identified