Slurtlesnailbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
This component defines the behavior tree for the Slurtle Snail entity (snurtle_snail). It manages autonomous decision-making including threat response (panic, running away, using shield), foraging (eating dropped food or stealing from inventories), and homing (returning to its home location when sufficiently hungry). It extends Brain and constructs a prioritized behavior tree on startup via OnStart, combining custom actions with reusable behaviors such as RunAway, Wander, and DoAction. It depends on several components (homeseeker, eater, inventory, burnable, knownlocations) to evaluate conditions and perform actions.
Usage example
This brain is intended to be attached to the snurtle_snail prefab definition. Typical usage involves assigning it during prefab setup as follows:
inst:AddComponent("brain")
inst.components.brain:SetBrain("slurtlesnailbrain")
No additional setup is required in external code; the brain initializes and runs autonomously once assigned.
Dependencies & tags
Components used:
homeseeker(readshome, checks validity and burning status)burnable(checksIsBurningstate of home)eater(validates food viaCanEat)inventory(finds and retrieves held/dropped food items)container(reads slots and numslots for stolen food containers)edible(validates edibility of items)knownlocations(retrieveshomelocation)
Tags: No tags are added or removed by this component.
Properties
The component inherits from Brain and does not define additional public properties in the constructor. Internal constants are declared at module scope but are not instance properties:
| Property | Type | Default Value | Description |
|---|---|---|---|
| (none) | - | - | No instance-level public properties are defined in the constructor. |
Main functions
SlurtleSnailBrain:OnStart()
- Description: Initializes the behavior tree for the snurtle_snail. Constructs a prioritized root node sequence that evaluates high-priority threats first (shield usage, panic triggers, running away), then feeding and stealing actions, followed by homing logic, and finally general wandering. The behavior tree is stored in
self.bt. - Parameters: None.
- Returns: None.
- Error states: If
homeseeker.homeis invalid or burning, theGoHomeActionreturnsnil, causing the "ShouldGoHome" priority branch to be skipped.
GoHomeAction(inst)
- Description: Helper action generator that returns a
BufferedActionto move to the snurtle's home if the home is valid and not burning; otherwise returnsnil. - Parameters:
inst: The entity instance (must havecomponents.homeseeker).
- Returns:
BufferedActionornil. - Error states: Returns
nilifhomeseekerorhomeis missing,homeis invalid, orhomeis burning.
EatFoodAction(inst)
- Description: Generates an eating action. First checks inventory for edible food; if not found, attempts to pick up food from the world. Returns
nilif no edible food is found or if the state graph has a "busy" tag. - Parameters:
inst: The entity instance (requirescomponents.inventoryandcomponents.eater).
- Returns:
BufferedAction(for EAT or PICKUP) ornil. - Error states: Returns
nilif no suitable food is found in inventory or world (within 30 units), or if the entity is currently in a "busy" state.
StealFoodAction(inst)
- Description: Scans entities within
SEE_FOOD_DIST(13 units) for inventories (player or container). Finds edible items in those inventories and attempts to steal one. Returns aBufferedAction(STEAL)withvalidfnandattack = true, ornil. - Parameters:
inst: The entity instance (requirescomponents.eaterandcomponents.inventory).
- Returns:
BufferedAction(for STEAL) ornil. - Error states: Returns
nilif no valid food is found in nearby inventories, or if the entity is in a "busy" state.
Events & listeners
This component does not register any event listeners or push events directly. Behavior and state transitions are driven entirely by the behavior tree evaluation loop (via BT).