Moonbutterflybrain
Based on game build 714014 | Last updated: 2026-02-27
Overview
This component implements the behavior tree for moonbutterfly entities. It defines priority-based decision-making, including panic responses (e.g., from electric fences or enemies with the scarytoprey tag), fleeing when threats approach within RUN_AWAY_DIST, homing to the remembered "home" location via Wander, and escaping dangerous situations. The brain relies on shared behavior logic (behaviours/ module) and external components (knownlocations, skilltreeupdater) to determine relevant state and context.
Dependencies & Tags
- Components used:
knownlocations— used to store and retrieve the "home" position viaRememberLocationandGetLocation.skilltreeupdater— checked to determine if thewormwood_bugsskill is activated, which modifies flee behavior.
- Tags:
- Checks for the
scarytopreytag on other entities to trigger fleeing. - The brain itself does not modify tags directly.
- Checks for the
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
RUN_AWAY_DIST | number | 5 | Distance threshold (units) at which the moonbutterfly begins fleeing from a threat. |
STOP_RUN_AWAY_DIST | number | 10 | Distance threshold (units) at which the moonbutterfly stops fleeing and resumes normal behavior. |
POLLINATE_FLOWER_DIST | number | 10 | Not used in this version of the brain. Likely reserved for future or variant logic. |
SEE_FLOWER_DIST | number | 30 | Not used in this version of the brain. |
MAX_WANDER_DIST | number | 20 | Maximum radius (units) from the "home" position the moonbutterfly will wander. |
inst | Entity | (inherited) | Reference to the entity this brain controls. |
bt | BehaviorTree | nil | Behavior tree instance; initialized in OnStart. |
Main Functions
GetHomePos(inst)
- Description: Helper function that retrieves the stored "home" position for the moonbutterfly using the
knownlocationscomponent. - Parameters:
inst— The entity instance whose home location is queried.
- Returns:
Vector— The position stored under the key"home"ininst.components.knownlocations.locations. Returnsnilif no home location is set.
ButterflyBrain:OnStart()
- Description: Initializes the behavior tree for the moonbutterfly. Builds a priority-based root node containing panic, flee, and wander behaviors. The behavior tree is only active while this function is called.
- Parameters: None.
- Returns: None.
- Notes:
- The behavior tree root prioritizes behaviors in this order:
BrainCommon.PanicTriggerBrainCommon.ElectricFencePanicTriggerRunAway— configured to flee entities with thescarytopreytag (unlesswormwood_bugsis activated).Wander— usesGetHomePosas the home reference andMAX_WANDER_DISTas the wander radius.
- The behavior tree root prioritizes behaviors in this order:
ButterflyBrain:OnInitializationComplete()
- Description: Records the moonbutterfly’s current position as its "home" location. This call happens after the entity is fully spawned and initialized.
- Parameters: None.
- Returns: None.
- Notes:
- Calls
RememberLocation("home", position, true)withdont_overwrite = true, ensuring the home position is set only once.
- Calls
Events & Listeners
None. This brain does not register or emit any events directly. It relies entirely on the behavior tree system and its integrated behaviors (e.g., RunAway, Wander) to react to world changes and triggers.