Wargbrain
Based on game build 714014 | Last updated: 2026-03-03
Overview
WargBrain implements the behavior tree logic for warg entities in Don't Starve Together. It orchestrates high-priority behaviors such as reanimating when near players (clay wargs), summoning hound minions, consuming carcasses, and engaging in combat. It integrates with the combat and burnable components and uses standard DST behavior modules (chaseandattack, leash, wander, standstill). The brain is shared between wargs and warglets, which rely on the SGhound state graph.
Usage example
local inst = CreateEntity()
inst:AddBrain("wargbrain")
-- Additional setup (tags, components, state graph) handled by prefab definition
Dependencies & tags
Components used: combat, burnable
Tags: Checks clay, lunar_aligned, creaturecorpse, NOCLICK, fire. Adds none directly.
Properties
No public properties are initialized in the constructor. Internal state is maintained in self.reanimatetime and self.carcass (set via method calls).
Main functions
SelectCarcass()
- Description: Locates the nearest valid corpse within
SEE_DIST(30 units) usingFindEntity, storing it inself.carcass. - Parameters: None.
- Returns:
trueif a matching corpse is found;falseotherwise. - Error states: May return
trueeven if the corpse becomes invalid before use (checked later byCheckCarcass).
CheckCarcass()
- Description: Verifies the currently stored
self.carcassis still valid and safe to consume (not burning). - Parameters: None.
- Returns:
trueifself.carcassis valid, has thecreaturecorpsetag, and is not burning;falseotherwise. - Error states: Returns
falseifself.carcassisnilor itsburnablecomponent reportsIsBurning().
GetCarcassPos()
- Description: Returns the 3D position of the target carcass, if it passes
CheckCarcass. - Parameters: None.
- Returns:
Vector3(viaself.carcass:GetPosition()) if carcass is valid;nilotherwise.
OnStart()
- Description: Initializes the behavior tree for the warg. Defines the root priority node tree with conditional and hierarchical logic, including state-specific behavior for intro, statue (clay), normal panic, hound summoning, carcass eating, combat, and wandering.
- Parameters: None.
- Returns: Nothing. Assigns the behavior tree to
self.bt.
Events & listeners
- Listens to: None directly (event handling is driven by the state graph
self.inst.sgviaHasStateTag,HandleEvent, andmem.dohowl). - Pushes:
"reanimate"with{ target = player }when reanimation trigger is satisfied (clay wargs)."chomp"with{ target = self.carcass }during carcass consumption (viaPushEventImmediate)."becomestatue"periodically when in clay state (viaPushEvent).
- Pushes via
BrainCommon:"panic"or"electricpanic"depending on configuration (not direct calls, but triggered viaPanicTriggerandElectricFencePanicTrigger).