Lightflierbrain
Based on game build 714014 | Last updated: 2026-03-03
Overview
Lightflierbrain defines the behavior tree logic for lightflier entities. It orchestrates movement, fleeing from threats (especially when not in formation), returning to a designated home (a lightflier_home tile), and syncs with the formationfollower component. It integrates with several components including homeseeker, locomotor, burnable, pickable, and childspawner, and uses helper behaviors like RunAway, Panic, Wander, and Follow.
Usage example
local inst = CreateEntity()
inst:AddBrain("lightflierbrain")
-- The brain automatically initializes upon stategraph entry via OnStart()
-- No direct instantiation or method calls are needed by modders.
Dependencies & tags
Components used: homeseeker, locomotor, formationfollower, burnable, pickable, childspawner, knownlocations
Tags added/checked: scarytoprey (via huntertags), lightflier_home (via NEW_HOME_TAGS), burnt, fire (excluded via NEW_HOME_NOTAGS), NOCLICK (excluded), busy (state tag check)
Properties
No public properties.
Main functions
OnStart()
- Description: Initializes the behavior tree with a hierarchical priority-based state machine. It configures locomotion and behavior based on formation status, threat proximity, and home conditions.
- Parameters: None.
- Returns: Nothing.
GoHomeAction(inst)
- Description: Constructs and returns a buffered
GOHOMEaction if conditions are met (e.g., home is valid, not burning, and not pickable), ornilotherwise. - Parameters:
inst(entity) — the lightflier entity. - Returns:
BufferedActionornil. - Error states: Returns
nilifinst.sg:HasStateTag("busy")is true, or if any required component or home condition fails.
FindHome(inst)
- Description: Ensures the
homeseekercomponent exists and assigns a validlightflier_hometile as the home if none is currently assigned. Takes ownership of the lightflier in the home’schildspawner. - Parameters:
inst(entity) — the lightflier entity. - Returns: Nothing.
ShouldGoHome(inst)
- Description: Determines whether the lightflier should return home. Returns
trueif the lightflier has just returned home (_lightflier_returning_home == inst) or if enough time has passed (>60seconds) and sufficient offspring are outside (numchildrenoutsideexceedsTUNING.LIGHTFLIER_FLOWER_TARGET_NUM_CHILDREN_OUTSIDE). - Parameters:
inst(entity) — the lightflier entity. - Returns:
boolean. - Error states: Returns
falseif home is invalid, not set, or conditions are not met.
Events & listeners
- Listens to:
panic— triggers a panic behavior and waits 6 seconds. - Pushes: None directly (events are handled internally via behaviors and the behavior tree).