Beebrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
The BeeBrain component implements the AI behavior tree for the Bee mob. It orchestrates high-level decision-making by evaluating environmental and state conditions (such as combat status, time of day, season, pollen load, and proximity to Bee Beacons or burning homes) and selecting appropriate behaviors. It inherits from Brain and uses a priority-based behavior tree constructed during OnStart. The brain interacts with several core components, including combat, homeseeker, burnable, pollinator, knownlocations, and various behavior modules (chaseandattack, runaway, wander, etc.).
Dependencies & Tags
- Components used:
combat: accessed viaself.inst.components.combat:HasTarget(),self.inst.components.combat:InCooldown(), andself.inst.components.combat.targethomeseeker: accessed viaself.inst.components.homeseeker.hometo check if the home is burningburnable: accessed viaself.inst.components.homeseeker.home.components.burnable:IsBurning()pollinator: accessed viaself.inst.components.pollinator:HasCollectedEnough()knownlocations: accessed viaself.inst.components.knownlocations:RememberLocation("home", ...)andself.inst.components.knownlocations:GetLocation("home")
- Tags: None are explicitly added or removed by this brain. Behavior tagging (e.g.,
"beebeacon") is used only for entity lookup viaFindEntity.
Properties
The constructor initializes only a few internal properties used for timed operations and caching:
| Property | Type | Default Value | Description |
|---|---|---|---|
beebeacontime | number | GetTime() + math.random() | Timestamp used to throttle how often the bee scans for a Bee Beacon (refreshed every ~2-3 seconds). |
No other public properties are defined directly in the constructor.
Main Functions
BeeBrain:OnStart()
- Description: Builds and assigns the behavior tree root node (
self.bt) by constructing a priority-ordered list of conditional behavior nodes. The tree evaluates conditions from highest to lowest priority and executes the first matching action. - Parameters: None.
- Returns: None. Installs the constructed
BTtree inself.bt.
BeeBrain:OnInitializationComplete()
- Description: Records the bee’s current position as the “home” location using the
knownlocationscomponent. This is called once after the entity is fully initialized and ready for AI use. - Parameters: None.
- Returns: None.
IsHomeOnFire(inst)
- Description: Helper function (not a method) that checks whether the bee’s home entity exists and is currently burning. Used as a condition in the behavior tree.
- Parameters:
inst: The bee entity instance.
- Returns:
boolean—trueif the home exists, is valid, and is burning; otherwisefalse.
FindBeeBeacon(self)
- Description: Caches and returns the nearest valid Bee Beacon within 30 world units. Uses throttling via
beebeacontimeto avoid frequent expensive searches (every 2–3 seconds). Invalidates the cached beacon if it becomes out-of-range or non–beebeacon-tagged. - Parameters:
self: The brain instance (providesself.inst,self.lastbeebeacon, andself.beebeacontime).
- Returns:
GameObject?— The found Bee Beacon entity, ornilif none exists or search is throttled.
GetBeeBeaconPos(self)
- Description: Convenience wrapper that returns the world position of the nearest Bee Beacon, or
nil. - Parameters:
self: The brain instance.
- Returns:
Vector3?— The beacon’sx,y,zposition, ornil.
GetRunAwayTarget(inst)
- Description: Returns the current combat target of the bee, used by the
RunAwaybehavior. - Parameters:
inst: The bee entity instance.
- Returns:
GameObject?— The entity targeting the bee (inst.components.combat.target), ornilif no target.
Events & Listeners
The BeeBrain component does not register any event listeners or push events. It relies solely on synchronous evaluation of conditions within the behavior tree nodes.