Brightmare Gestaltguardbrain
Based on game build 722832 | Last updated: 2026-04-27
Overview
Brightmare Gestaltguardbrain is the AI behaviour tree for the brightmare gestalt guard entity. It prioritises aggressive chasing at behaviour_level == 3, relocates when players get too close (within RELOCATED_DISTSQ), attempts chassis possession via BrainCommon.PossessChassisNode, faces valid combat targets within watching range, and wanders idly otherwise. Brains are paused when the entity is far from any player and resume automatically on player proximity. Brain trees are attached via inst:SetBrain(brain) during prefab construction.
Usage example
-- Brains are attached during prefab construction:
local brain = require("brains/brightmare_gestaltguardbrain")
inst:SetBrain(brain)
-- The framework calls OnStart() to obtain the behaviour tree.
-- Manual access to the running tree:
if inst.brain ~= nil and inst.brain.bt ~= nil then
-- inspect or reset the running behaviour tree
end
Dependencies & tags
External dependencies:
behaviours/follow-- imported but not directly used in visible codebehaviours/wander-- Wander behaviour node factorybehaviours/standstill-- StandStill behaviour node factorybehaviours/faceentity-- FaceEntity behaviour node factorybrains/braincommon-- providesPossessChassisNodefor chassis possession logic
Components used:
combat-- read current target viainst.components.combat.targetknownlocations-- records spawn point viaRememberLocationinOnInitializationCompletesg(stategraph) -- checked forjumpingtag and triggersrelocatestate
Tags:
jumping-- checked viaHasStateTagto gate main behaviour tree execution
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
ATTACK_CHASE_TIME | constant (local) | 5 | Duration in seconds for ChaseAndAttack behaviour when behaviour_level == 3. |
WANDER_TIMES | constant (local) | { minwalktime = 2, randwalktime = 2, minwaittime = 3, randwaittime = 3 } | Timing parameters for Wander behaviour: walk and wait time ranges. |
RELOCATED_DISTSQ | constant (local) | 9 | Squared distance threshold (3*3) for detecting players too close, triggering relocation. |
GETFACINGTARGET_DISTSQ | constant (local) | TUNING.GESTALTGUARD_WATCHING_RANGE^2 | Squared distance threshold for determining if a combat target is within facing range. |
UPDATE_RATE | constant (local) | 0.1 | Behaviour tree update interval in seconds for PriorityNode and WhileNode evaluations. |
Main functions
OnStart()
- Description: Constructs the root PriorityNode of the behaviour tree with nested WhileNodes gating behaviour by state and level. Priority order: aggressive chase (level 3) > relocate (player too close) > chassis possession > face entity > wander. The entire tree is wrapped in a WhileNode that skips execution if the entity has the
jumpingstate tag. Called once when the brain is attached and on resume after pause. - Parameters: None
- Returns: None (assigns
self.btwith the BehaviourTree) - Error states: Errors if
self.inst.sgis nil when checkingHasStateTag(no nil guard present beforeself.inst.sg:HasStateTagcall).
OnInitializationComplete()
- Description: Records the entity's spawn point location in the
knownlocationscomponent with the name"spawnpoint". Usesdont_overwrite = trueto prevent overwriting existing spawn point data. Called once after the brain is fully initialized. - Parameters: None
- Returns: None
- Error states: Errors if
self.inst.components.knownlocationsis nil or missing. Errors ifself.inst:GetPosition()returns invalid coordinates.
IsPlayerTooClose(inst) (local)
- Description: Helper passed to the Relocate WhileNode. Returns true if any player is within
RELOCATED_DISTSQ(squared distance of 9 tiles) of the entity. UsesIsAnyPlayerInRangeSqwith the final boolean parameter set totrue. - Parameters:
inst-- entity owning the brain - Returns: boolean -- true if a player is within the relocation threshold distance
- Error states: Errors if
inst.Transformis nil orinst.Transform:GetWorldPosition()fails.
Relocate(inst) (local)
- Description: Helper passed to the Relocate ActionNode. Triggers the
relocatestate on the entity's stategraph, causing the entity to move to a new position away from nearby players. - Parameters:
inst-- entity owning the brain - Returns: None
- Error states: Errors if
inst.sgis nil orinst.sg:GoToStateis unavailable.
GetFacingTarget(inst) (local)
- Description: Helper passed to the FaceEntity behaviour node. Returns the current combat target if
behaviour_level == 2and the target is withinGETFACINGTARGET_DISTSQ. Calculates squared distance between entity and target positions (ignoring Y axis). Returns nil if no valid target or target is out of range. - Parameters:
inst-- entity owning the brain - Returns: entity instance or
nilif no valid target within range - Error states: Errors if
inst.components.combatis nil. Errors ifinst.Transformortarget.Transformis nil when getting positions.
KeepFacingTarget(inst, target) (local)
- Description: Helper passed to the FaceEntity behaviour node. Validates whether the entity should continue facing the given target by checking if
GetFacingTarget(inst)still returns the same target. Used to determine if the facing behaviour should persist or be cancelled. - Parameters:
inst-- entity owning the braintarget-- candidate target entity to validate
- Returns: boolean -- true if target is still valid for facing
- Error states: Errors if
GetFacingTargetfails due to missing components (seeGetFacingTargeterror states).
Events & listeners
None — brain trees react to component state, not engine events directly. Event handling is done in the brain's host stategraph or via component subscriptions.