Smallbirdbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The SmallBirdBrain component implements the decision-making logic for small bird entities in Don't Starve Together. It uses a behavior tree to prioritize actions based on hunger, leader presence, combat status, and proximity to players. The brain integrates with several components — hunger, follower, combat, eater, and trader — to dynamically select appropriate actions such as wandering, following a leader, fleeing players, seeking food, or attacking targets. This brain is part of the Entity Component System (ECS), attached via inst:AddComponent("brain") and used exclusively during entity runtime to drive AI behavior.
Usage example
local inst = Entity(entityid)
inst:AddComponent("hunger")
inst:AddComponent("follower")
inst:AddComponent("combat")
inst:AddComponent("eater")
inst:AddComponent("trader")
inst:AddTag("teenbird")
inst:AddTag("companion")
inst:AddBrain("smallbirdbrain")
Dependencies & tags
Components used: combat, eater, follower, hunger, trader
Tags: teenbird, companion, INLIMBO, outofreach
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil (passed to constructor) | Reference to the entity instance the brain controls |
bt | BT | nil (initialized in OnStart) | Behavior tree instance used for decision making |
Main functions
SmallBirdBrain:OnStart()
- Description: Initializes the behavior tree with a priority-ordered list of tasks. This is the entry point for AI behavior setup and is called once when the brain is first activated.
- Parameters: None
- Returns:
nil - Error states: None documented; relies on valid component presence and tags.
Helper Functions (Internal)
GetLeader(inst)
- Description: Retrieves the leader of the entity if
followercomponent exists. - Parameters:
inst(Entity) — the entity to inspect. - Returns:
Entity?— the leader entity, ornil. - Error states: Returns
niliffollowercomponent is missing or no leader is set.
IsHungry(inst)
- Description: Checks if the entity’s hunger level is below
FIND_FOOD_HUNGER_PERCENT. - Parameters:
inst(Entity) — the entity to inspect. - Returns:
boolean—trueif hunger percent <0.75, otherwisefalse. - Error states: Returns
falseifhungercomponent is missing.
IsStarving(inst)
- Description: Checks if the entity is currently starving (
hunger <= 0). - Parameters:
inst(Entity) — the entity to inspect. - Returns:
boolean—trueifhunger:IsStarving()returnstrue, otherwisefalse. - Error states: Returns
falseifhungercomponent is missing.
ShouldStandStill(inst)
- Description: Determines if the entity should remain stationary, e.g., when starving and not a teenbird or not accompanied by a tallbird leader.
- Parameters:
inst(Entity) — the entity to inspect. - Returns:
boolean—trueif starvation and noteenbirdtag, or leader is not a tallbird; otherwisefalse. - Error states: Returns
falseifhungercomponent is missing.
CanSeeFood(inst)
- Description: Searches within
SEE_FOOD_DISTfor an edible item on valid ground, usingeater:CanEatandItem:IsOnValidGround. - Parameters:
inst(Entity) — the entity performing the search. - Returns:
Entity?— the first edible item found, ornil. - Error states: Returns
nilif no matching item exists, or ifeatercomponent is missing.
FindFoodAction(inst)
- Description: Returns a
BufferedActionto eat a visible food item if available. - Parameters:
inst(Entity) — the entity initiating the action. - Returns:
BufferedAction?— action to eat the target, ornilif no food is visible. - Error states: Returns
nilifCanSeeFood(inst)returnsnil.
GetTraderFn(inst)
- Description: Determines if the entity or its leader is currently being offered a trade.
- Parameters:
inst(Entity) — the entity to inspect. - Returns:
Entity?— the leader if trading is in progress and entity hascompaniontag; otherwisenil. - Error states: Returns
nilif no leader, notradercomponent, or no trade action initiated.
KeepTraderFn(inst, target)
- Description: Verifies if
targetis actively trying to trade withinst. - Parameters:
inst(Entity) — the entity being traded with.target(Entity) — the proposed trading partner.
- Returns:
boolean—trueiftrader:IsTryingToTradeWithMe(target)returnstrue. - Error states: Returns
falseiftradercomponent is missing.
ShouldRunAwayFromPlayer(inst, player)
- Description: Decides if the entity should flee from a given player.
- Parameters:
inst(Entity) — the entity being evaluated.player(Entity) — the player entity.
- Returns:
boolean—trueif entity has no leader and lackscompaniontag; otherwisefalse. - Error states: None documented.
Events & listeners
None. The component does not register or fire any events directly. Behavior updates are driven by the behavior tree evaluation loop.