Sgbrightmare Gestalt
Based on game build 722832 | Last updated: 2026-04-27
Overview
SGbrightmare_gestalt is an animation state machine attached to the gestalt prefab. It governs idle, walk, emerge, attack, death, relocation, and capture animations while reacting to engine events such as locomote, doattack, gestaltcapturable_targeted, and captured. Stategraphs are attached via StartStateGraph(inst, "sgname") during prefab construction, not called as utility functions. Major state categories: locomotion (idle, walk, emerge), combat (attack, guardattack), lifecycle (death, relocate, captured), and transformation (mutate_pre).
Usage example
-- Stategraphs are attached to a prefab during construction:
inst.sg = StartStateGraph(inst, "gestalt")
-- Trigger a state from external code:
inst.sg:GoToState("attack")
-- Query state-tag membership:
if inst.sg:HasStateTag("busy") then
return
end
-- Listen for stategraph events from a component:
inst:ListenForEvent("doattack", function(inst, data)
-- Attack triggered
end)
-- Listen for attacked event (pushed by DoSpecialAttack):
inst:ListenForEvent("attacked", function(inst, data)
-- Target was attacked
end)
Dependencies & tags
External dependencies:
stategraphs/commonstates-- shared locomotion/death state factories and common event handlers
Components used:
locomotor-- Stop(), WantsToMoveForward() queried for movement state during transitionsgestaltcapturable-- IsTargeted(), SetEnabled() to control capture availabilitycombat-- target, StartAttack(), DropTarget(), CanTarget(), DoAttack() for attack logicsanity-- DoDelta() applied to attack targetsgrogginess-- AddGrogginess() applied to attack targets
Tags:
idle-- added in idle statemoving-- added in walk states (via CommonStates)busy-- added in attack/emerge/death/relocate/captured states to block other transitionsnoattack-- added in non-combat states to prevent attack triggeringattack-- added on attack onenterjumping-- added in attack/guardattack/mutate_pre statescanrotate-- added in idle/emerge/relocate stateshidden,invisible-- added in relocating statenointerrupt-- added in captured stateNOCLICK-- added in captured state to prevent player interaction
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
| None | -- | -- | This stategraph has no file-scope local constants to document. |
Main functions
onenter (idle)
- Description: Stops locomotion and plays the idle animation. Sets
idleandcanrotatetags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.locomotororinst.AnimStateis nil (no nil guard present).
onenter (emerge)
- Description: Stops locomotion, plays the emerge animation, and disables gestaltcapturable to prevent capture during emergence. Sets
busy,noattack, andcanrotatetags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.locomotor,inst.AnimState, orinst.components.gestaltcapturableis nil (no nil guard present).
onexit (emerge)
- Description: Re-enables gestaltcapturable after emergence completes.
- Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.gestaltcapturableis nil (no nil guard present).
onenter (death)
- Description: If entity is asleep, removes it immediately. Otherwise stops locomotion, plays melt animation, sets
persists = false, and disables gestaltcapturable. Setsbusyandnoattacktags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.locomotor,inst.AnimState, orinst.components.gestaltcapturableis nil (no nil guard present).
onexit (death)
- Description: Re-enables gestaltcapturable (should not be reached in normal flow).
- Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.gestaltcapturableis nil (no nil guard present).
onenter (relocate)
- Description: Stops locomotion, plays melt animation, and disables gestaltcapturable. Sets
busy,noattack, andcanrotatetags. Transitions torelocatingstate after animation completes. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.locomotor,inst.AnimState, orinst.components.gestaltcapturableis nil (no nil guard present).
onexit (relocate)
- Description: Re-enables gestaltcapturable only if relocation did not complete (statemem.relocating is false).
- Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.gestaltcapturableis nil (no nil guard present).
onenter (relocating)
- Description: Stops locomotion, hides the entity, disables gestaltcapturable, and sets a random timeout between 0.25 and 0.75 seconds. Sets
busy,noattack,hidden, andinvisibletags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.locomotororinst.components.gestaltcapturableis nil (no nil guard present).
ontimeout (relocating)
- Description: If
_can_despawnis set, removes the entity. Otherwise finds a relocate point and transitions toemergestate, or removes entity if no valid destination found. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: None
onexit (relocating)
- Description: Shows the entity and sets position to the stored destination if available. Otherwise re-enables gestaltcapturable.
- Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: None
onenter (attack)
- Description: Plays attack animation, stops locomotion, forces facing toward combat target if present, and starts attack cooldown. Sets
busy,noattack,attack, andjumpingtags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.combatis nil -- no nil guard beforeinst.components.combat.targetaccess.
onupdate (attack)
- Description: During the attack window (enable_attack flag set), finds the best attack target using
FindBestAttackTarget(). If a target is found, applies special attack effects (sanity/grogginess damage), drops combat target, and transitions tomutate_prestate. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.combatis nil (no nil guard present beforeDropTarget()call).
onexit (attack)
- Description: Clears motor velocity override, stops locomotion, and drops combat target if attack did not land.
- Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.Physics,inst.components.locomotor, orinst.components.combatis nil (no nil guard present).
onenter (guardattack)
- Description: Plays attack animation, stops locomotion, forces facing toward combat target if present, and starts attack cooldown. Sets
busy,noattack,attack, andjumpingtags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.combatis nil -- no nil guard beforeinst.components.combat.targetaccess.
onupdate (guardattack)
- Description: During the attack window, checks if combat target is valid and within hit range. If target can be attacked, performs attack and transitions to
mutate_prestate with speed parameter 6. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.combatis nil (no nil guard present before target access or method calls).
onexit (guardattack)
- Description: Clears motor velocity override and stops locomotion.
- Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.Physicsorinst.components.locomotoris nil (no nil guard present).
onenter (mutate_pre)
- Description: Sets motor velocity override (default speed 2, or provided speed parameter), plays mutate animation, and sets
persists = false. Setsbusy,noattack, andjumpingtags. - Parameters:
inst-- entity owning the stategraphspeed-- optional movement speed (default2)
- Returns: nil
- Error states: Errors if
inst.Physicsorinst.AnimStateis nil (no nil guard present).
onenter (captured)
- Description: Stops locomotion, plays melt animation at frame 1 with 2x delta time multiplier, and adds
NOCLICKtag. Setsbusy,noattack, andnointerrupttags. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.components.locomotororinst.AnimStateis nil (no nil guard present).
onexit (captured)
- Description: Resets delta time multiplier to 1x and removes
NOCLICKtag (should not be reached in normal flow). - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.AnimStateis nil (no nil guard present).
FindBestAttackTarget(inst) (local)
- Description: Searches all players for the closest valid attack target within
TUNING.GESTALT_ATTACK_HIT_RANGE_SQ. Excludes dead/ghost players and players with knockout/sleeping/bedroll/tent/waking state tags. - Parameters:
inst-- entity owning the stategraph - Returns: Player entity or
nilif no valid target found. - Error states: Errors if
inst.Transformis nil (no nil guard present beforeGetWorldPosition()call).
DoSpecialAttack(inst, target) (local)
- Description: Applies sanity damage and grogginess to the target. If grogginess component exists, adds grogginess value and knockout time. Pushes
attackedevent with zero damage (special attack does not deal health damage). - Parameters:
inst-- attacker entitytarget-- target entity
- Returns: nil
- Error states: None -- nil guards present for sanity and grogginess components.
SpawnTrail(inst) (local)
- Description: Spawns a
gestalt_trailprefab at the entity's position and rotation. Skipped if_notrailflag is set. - Parameters:
inst-- entity owning the stategraph - Returns: nil
- Error states: Errors if
inst.Transformis nil (no nil guard present beforeGetWorldPosition()/GetRotation()calls).
Events & listeners
- Listens to:
locomote-- transitions towalk_startif moving and not targeted, orwalk_stopif currently moving. - Listens to:
gestaltcapturable_targeted-- transitions towalk_stopif currently moving. - Listens to:
doattack-- transitions toguardattack(if isguard) orattackstate if not busy. - Listens to:
captured-- interrupts any state and transitions tocapturedstate. - Listens to:
death(via CommonHandlers) -- transitions to death state. - Pushes:
attacked-- fired byDoSpecialAttackwhen target has no grogginess or knockout duration is zero.