Moosebrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
This component implements the behavior tree for the moose entity in Don't Starve Together. It orchestrates high-level behaviors such as fleeing (shouldGoAway), leash tracking, chasing and attacking targets, laying eggs, facing nearby players, and wandering near a designated home location (landpoint). It inherits from Brain and constructs a BT (Behavior Tree) in OnStart() using priority-ordered behavior nodes defined in external behavior modules.
The moosebrain relies on several external components: Combat for target tracking, KnownLocations for home/landmark positions, and EntityTracker for locating related entities like eggs. It integrates with the behaviours module to delegate specific behavioral tasks (e.g., ChaseAndAttack, FaceEntity, Leash, Wander).
Dependencies & Tags
- Components used:
Combat(viaself.inst.components.combat)KnownLocations(viaself.inst.components.knownlocations)EntityTracker(viaself.inst.components.entitytracker)
- Tags:
- Checks:
"notarget","busy"(viainst:HasTag("notarget"),self.inst.sg:HasStateTag("busy")) - Sets:
"busy"is only read (no tag modification logic present in this script)
- Checks:
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst.shouldGoAway | boolean | nil (checked dynamically) | Indicates whether the moose should flee/halt aggressive behavior and return home. |
inst.WantsToLayEgg | boolean | nil (checked dynamically) | Controls whether the moose attempts to lay an egg. |
inst.sg | StateGraph | — | The state graph instance; used to check busy state tag. |
self.bt | BT | nil (assigned in OnStart) | The behavior tree constructed in OnStart(). |
Main Functions
GoHome(inst)
- Description: Returns a buffered
ACTIONS.GOHOMEaction if the moose is in "go away" mode and has no active combat target; otherwise returnsnil. - Parameters:
inst— the moose entity instance. - Returns:
BufferedAction(if conditions are met) ornil.
GetFaceTargetFn(inst)
- Description: Finds the closest player within
START_FACE_DIST(15 units) that does not have the"notarget"tag, provided the moose is not currently in a "busy" state. Used by theFaceEntitybehavior to select a new target to face. - Parameters:
inst— the moose entity instance. - Returns:
Entity(if found) ornil.
KeepFaceTargetFn(inst, target)
- Description: Determines whether to continue facing a given target. Returns
trueonly if the moose is not in a "busy" state, does not have"notarget", and is withinKEEP_FACE_DIST(20 units) of the target. - Parameters:
inst— the moose entity instance.target— the entity currently being faced.
- Returns:
boolean.
LayEgg(inst)
- Description: Returns a buffered
ACTIONS.LAYEGGaction if the moose wishes to lay an egg and no egg entity has been registered yet viaEntityTracker. - Parameters:
inst— the moose entity instance. - Returns:
BufferedAction(if conditions are met) ornil.
MooseBrain:OnStart()
- Description: Initializes the behavior tree with a priority-based root node that evaluates (in order):
- Flee if
shouldGoAwayis true (callsGoHome). - Enforce leash distance (25 units) from the
"landpoint"location. - Chase and attack the current combat target.
- Attempt egg laying.
- Face a target (via
GetFaceTargetFnandKeepFaceTargetFn). - Wander within 15 units of
"landpoint".
The lowest-priority node isWander. This function must be called by the game when the moose enters the world.
- Flee if
- Parameters: None.
- Returns: None.
MooseBrain:OnInitializationComplete()
- Description: Records the moose's initial position as
"spawnpoint"inKnownLocationsusingRememberLocation. Ensures the spawn location is stored before gameplay proceeds. - Parameters: None.
- Returns: None.
Events & Listeners
None.