Lightcrabbrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The LightCrabBrain component defines the behavior tree for lightcrab entities. It inherits from Brain and orchestrates high-priority reactive behaviors—including panic responses to nearby players or electric fences, food consumption when bait is present, and a fallback wander state—using a prioritized sequence of behavior nodes. It integrates with the homeseeker component to enable returning to a designated home location, and relies on the eater and bait components to validate edible items during foraging.
Dependencies & Tags
- Components used:
homeseeker(accessed viainst.components.homeseekerforhomeproperty andIsValidcheck)eater(accessed viaitem.components.eater:CanEat(item))bait(accessed viaitem.components.baitexistence)
- Tags checked:
"INLIMBO"(excluded viaFINDFOOD_CANT_TAGS)"outofreach"(excluded viaFINDFOOD_CANT_TAGS)"trapped"(checked viaself.inst.sg:HasStateTag("trapped"))"planted"(excluded via direct tag check on target item)
- Tags added/removed: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | Entity | nil | The entity instance this brain controls, inherited from Brain. |
bt | BT | nil | Behavior tree root assigned in OnStart. |
AVOID_PLAYER_DIST | number | 5 | Distance threshold at which the crab initiates fleeing from a player. |
AVOID_PLAYER_STOP | number | 9 | Distance at which fleeing ceases after initiating. |
SEE_BAIT_DIST | number | 5 | Search radius for edible bait items. |
FINDFOOD_CANT_TAGS | table | { "INLIMBO", "outofreach" } | Tags that disqualify entities from being considered as food targets. |
WANDER_TIMING | table | { minwaittime = 10, randwaittime = 10 } | Timing parameters for the wander behavior (min wait + random offset). |
Main Functions
GoHomeAction(inst)
- Description: Constructs a
BufferedActionthat triggersACTIONS.GOHOMEon the home location if the home exists, is valid, and the crab is not currently trapped. - Parameters:
inst(Entity): The lightcrab instance requesting the action.
- Returns: A
BufferedActionobject ornilif conditions are unmet.
EatFoodAction(inst)
- Description: Searches for the nearest entity within
SEE_BAIT_DISTthat is edible (eater:CanEat), has abaitcomponent, is not planted, is on a passable point, and resides on the same platform. Returns a buffered eat action if such an item is found. - Parameters:
inst(Entity): The lightcrab instance requesting the action.
- Returns: A
BufferedActionforACTIONS.EATwith avalidfncheck against limbo state, ornil.
LightCrabBrain:OnStart()
- Description: Initializes the behavior tree with a priority-based sequence of nodes. The root prioritizes:
- Immediate response while in a
"jumping"state (standby). - Panic triggers for nearby players and electric fences (via
BrainCommon). - Runaway behavior (
RunAway) when withinAVOID_PLAYER_DIST. - Eating bait (
DoActionwithEatFoodAction). - Default wandering behavior (
Wander).
- Immediate response while in a
- Parameters: None.
- Returns: None. Assigns
self.btto aBTinstance using the constructed root node.
Events & Listeners
None identified.