Beeguardbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The BeeGuardBrain component implements the decision-making logic for the Beeguard entity in Don't Starve Together. As a brain, it orchestrates a behavior tree (BT) that dynamically selects high-priority actions based on game state and environment conditions. Its core responsibilities include maintaining defensive proximity to the queen, engaging hostile targets within aggro range, evading hazards like electric fences, reacting to panic triggers, and reverting to idle wandering when appropriate.
Key relationships:
- It extends
Brainand relies onBrainCommonfor shared state evaluation (e.g., panic, electric fence avoidance). - It integrates with the
Combatcomponent to manage targeting and attack readiness. - It consults the
Healthcomponent to determine target validity during flight decisions. - It queries
KnownLocationsto retrieve the queen’s positional offset for formation control.
Dependencies & Tags
- Components used:
inst.components.combat— to query/set target, check cooldowns, and validate targets.inst.components.health— to verify if a target is alive.inst.components.knownlocations— to fetch thequeenoffsetlocation.inst:GetQueen()— an entity method (inherited or defined on Beeguard) returning the queen entity.
- Tags used in filtering:
"_combat","_health"— included inRUN_AWAY_PARAMSfor behavior selection."bee","playerghost","INLIMBO"— excluded (negated vianotags) from run-away candidates."player"— included as a source of threat.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_shouldchase | boolean | false | Internal flag indicating whether the beeguard is currently committed to chasing (used to extend aggro range when active). |
Main Functions
GetQueen(inst)
- Description: Helper function that retrieves the queen entity associated with this beeguard via
inst:GetQueen(). - Parameters:
inst: The beeguard entity instance.
- Returns: The queen entity, or
nilif none exists.
GetQueenPos(inst)
- Description: Retrieves the current world position of the queen, if available.
- Parameters:
inst: The beeguard entity instance.
- Returns: A vector position (
pos) if the queen exists, otherwisenil.
GetQueenOffset(inst)
- Description: Retrieves the queen’s positional offset (relative coordinate) stored in
KnownLocations. - Parameters:
inst: The beeguard entity instance.
- Returns: The offset vector, or
nilif not set.
GetGuardPos(inst)
- Description: Calculates the absolute world position the beeguard should guard by adding the queen’s offset to the queen’s position.
- Parameters:
inst: The beeguard entity instance.
- Returns: A vector position, or
nilif either queen or offset is missing.
ShouldPanic(self)
- Description: Determines if the beeguard should enter panic mode (e.g., due to extreme danger or environmental threat).
- Parameters:
self: The brain component instance.
- Returns:
trueifBrainCommon.ShouldTriggerPanic(self.inst)returnstrueand_shouldchaseis set tofalse; otherwisefalse.
ShouldAvoidElectricFence(self)
- Description: Determines if the beeguard should avoid electric fences using shared logic.
- Parameters:
self: The brain component instance.
- Returns:
trueifBrainCommon.ShouldAvoidElectricFence(self.inst)returnstrueand_shouldchaseis set tofalse; otherwisefalse.
ShouldChase(self)
- Description: Evaluates whether the beeguard should break formation and engage in combat. The decision considers the presence of a valid target, proximity to the queen, and current aggro range.
- Parameters:
self: The brain component instance.
- Returns:
trueif:- The queen is missing, offset is missing, a focus target (
_focustarget) exists, or - The current
Combattarget is valid, alive, and within extended aggro distance (TUNING.BEEGUARD_AGGRO_DIST + (self._shouldchase and 3 or 0)). In all other cases, returnsfalseand clears the combat target.
- The queen is missing, offset is missing, a focus target (
ShouldDodge(inst)
- Description: Checks if the beeguard should dodge incoming attacks (e.g., during a damage cooldown).
- Parameters:
inst: The beeguard entity instance.
- Returns:
trueif the beeguard has a combat target and is currently in its attack cooldown period (InCooldown()returnstrue).
ShouldHoldFormation(inst)
- Description: Determines if the beeguard should remain in defensive position near the queen.
- Parameters:
inst: The beeguard entity instance.
- Returns:
trueif both the queen entity and queen offset are present; otherwisefalse.
BeeGuardBrain:OnStart()
- Description: Initializes the behavior tree with a priority-based node structure that dictates high-priority responses before falling back to idle behavior.
- Parameters: None.
- Returns: None. Sets
self.btto a constructed behavior tree instance.- Behavior tree priority order:
- Panic: Overrides all if
ShouldPanic()returnstrue. - AvoidElectricFence: Activates if
ShouldAvoidElectricFence()returnstrue. - BreakFormation: Activates if
ShouldChase()returnstrue; sub-prioritizes dodging (ifShouldDodge()istrue) over direct attack. - HoldFormation: Moves and orients the beeguard near the queen if
ShouldHoldFormation()returnstrue. - Wander: Default idle behavior if none above apply.
- Panic: Overrides all if
- Behavior tree priority order:
Events & Listeners
None identified.
Additional Notes
- All behaviors (e.g.,
Panic,ChaseAndAttack,Leash,Wander,AvoidElectricFence,RunAway) are imported from thebehaviours/directory. - The
RUN_AWAY_PARAMSconfiguration defines specific filtering criteria for entities that cause the beeguard to flee. Notably, only entities that either are players or have a bee as their own combat target are considered threats. - Aggro distance dynamically increases by 3 units when
_shouldchaseistrue, allowing the beeguard to stay engaged during prolonged fights. FaceAwayFromPointis used inHoldFormationto orient the beeguard away from the queen (i.e., “back-to-back” defensive stance).