Wobysmallbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The WobySmallBrain component defines the behavior tree logic for the small Woby variant, a companion entity in Don't Starve Together. It orchestrates decision-making using a priority-based behavior tree (BT) to manage state transitions between following its owner, avoiding nearby combat, playing with other critters, showing affection, and performing helper tasks (foraging, retrieving ammo, etc.). It integrates closely with the Follower, Combat, Locomotor, Sleeper, and CritterTraits components, and relies on several custom behaviors from the behaviours/ directory and shared helper functions from wobycommon.lua.
Usage example
Typically instantiated by adding the component to a Woby entity during its prefab definition:
inst:AddComponent("wobysmallbrain")
The component automatically initializes its behavior tree when the entity enters the world and begins execution. No manual function calls are required; behavior transitions are driven internally via the behavior tree root node.
Dependencies & tags
Components used:
follower— for retrieving the owner viaGetLeader()combat— for detecting active combat and timingcrittertraits— for checking dominant "playful" trait viaIsDominantTraitgrouptargeter— for verifying if another entity is targeting the ownerlocomotor— for checking movement intent viaWantsToMoveForwardsleeper— for verifying if a potential playmate is asleep
Tags:
flying— used during playmate selection to bypass ground pathing constraintsbusy— used to block affection and playmate interactions via state tags_combat,_health,wall,INLIMBO— used internally during entity filtering in combat avoidance
Properties
No explicit public properties are defined in the constructor beyond the inherited behavior tree state. All state is stored on self within the behavior tree root definition.
Main functions
WobySmallBrain:OnStart()
- Description: Constructs and assigns the root behavior tree (
self.bt) used for decision-making. Defines a multi-level priority structure handling combat avoidance, recall, helper tasks, playful interactions, affection, and idle states. - Parameters: None.
- Returns: None.
- Error states: None known; behavior tree root must be non-nil for AI execution.
GetOwner(inst)
- Description: Helper function that returns the owner of the instance by querying
inst.components.follower:GetLeader(). - Parameters:
inst— the entity instance. - Returns: The leader entity or
nilif no owner is assigned. - Error states: Returns
nilif thefollowercomponent is missing orGetLeader()returnsnil.
OwnerIsClose(inst, distance)
- Description: Checks whether the owner is within a given distance (default
MAX_FOLLOW_DIST = 4.5). - Parameters:
inst— the entity instance.distance(optional) — numeric threshold for distance check.
- Returns:
trueif owner exists and is within distance; otherwisefalse. - Error states: Returns
falseifGetOwner(inst)returnsnil.
LoveOwner(inst)
- Description: Attempts to perform a "nuzzle" action toward the owner if conditions (not busy, owner not a ghost, cooldown passed, and luck roll succeeds) are met.
- Parameters:
inst— the entity instance. - Returns: A
BufferedActionresult ornil. - Error states: Returns
nilif any condition fails (e.g.,busystate tag, invalid owner, cooldown active, or luck failure).
TargetCanPlay(self, target, owner, max_dist_from_owner, is_flier)
- Description: Validates whether a target entity can be selected as a playmate based on playfulness, proximity, ground availability, and sleep state.
- Parameters:
self— the brain instance (used for trait checks).target— candidate entity.owner— the owner entity.max_dist_from_owner— maximum distance the target can be from the owner to be valid.is_flier— whether the owner can ignore ground constraints.
- Returns:
trueif the target satisfies all play criteria; otherwisefalse. - Error states: Returns
falseiftarget.IsPlayfulis notnilandtarget:IsPlayful()returnsfalse, or iftarget.components.sleeper:IsAsleep()istrue.
FindPlaymate(self)
- Description: Attempts to locate or retain a valid playmate within proximity of the owner. Prioritizes current playmate if still valid, otherwise searches for new playmates based on dominant trait and location.
- Parameters:
self— the brain instance. - Returns:
trueif a playmate is found or retained;falseotherwise. - Error states: May return
falseif no candidate meetsTargetCanPlay, owner is far away, or owner is moving (WantsToMoveForward()istrue).
_avoidtargetfn(self, target)
- Description: Determines whether a given entity is a threat requiring avoidance. Considers active combat, recent combat timing, and proximity to the owner.
- Parameters:
self— the brain instance. - Returns:
trueiftargetshould be avoided; otherwisefalse. - Error states: Returns
falseif either owner ortargetlackscombatcomponent, or if combat distance thresholds are exceeded.
ValidateCombatAvoidance(self)
- Description: Verifies whether the current
runawayfromtarget is still a valid threat and within effective range. Fires"critter_avoidcombat"events as needed. - Parameters:
self— the brain instance. - Returns:
trueif combat avoidance remains active; otherwisefalse. - Error states: Sets
self.runawayfrom = niland emits"critter_avoidcombat"with{avoid=false}if the threat is no longer valid or out of range.
CombatAvoidanceFindEntityCheck(self)
- Description: Returns a predicate function used by
FindEntityto locate threats requiring avoidance. - Parameters:
self— the brain instance. - Returns: A function
function(ent) ... endthat evaluates whetherentshould be avoided. - Error states: Emits
"critter_avoidcombat"with{avoid=true}upon finding a threat.
PlayWithPlaymate(self)
- Description: Fires the
"start_playwithplaymate"event with the currentplayfultargetto notify systems of the start of playful interaction. - Parameters:
self— the brain instance. - Returns: None.
- Error states: None known.
Events & listeners
- Listens to:
- None explicitly defined in this file (the component does not register listeners for external events directly).
- Pushes:
"critter_avoidcombat"— fired with{avoid=true}when a threat is first detected, and{avoid=false}when avoidance is no longer needed."start_playwithplaymate"— fired when a valid playmate interaction begins, including theplayfultargetin the event data.
Note: While
inst:ListenForEventis not called directly here, listeners are likely registered via external stategraph or prefabs using this brain. This file only defines the brain logic, not event subscription.