Sgchester
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGchester is the state graph for the Chester mob, handling its core behaviors including movement (bouncing/walking), opening/closing animations, transformation via morph, and special states like knockbacklanded and devoured. It integrates heavily with the locomotor component for bouncing physics, the container/container_proxy component for open/close state and interaction, and the freezable component to handle status effects. It also spawns visual effects (e.g., slime trails, morph FX) and manages sound playback for transitions and panting.
Usage example
This stategraph is applied automatically to the Chester prefab during entity initialization. Modders typically interact with it via events (e.g., triggering morph or knockback), not by directly calling its state functions. Example usage:
-- Trigger Chester's morph transformation with a custom function
inst:PushEvent("morph", { morphfn = function(chester) chester:CustomMorph() end })
-- Simulate a knockback impact
inst:PushEvent("knockback", {
knocker = attacker,
radius = 1.0,
strengthmult = 1.2,
})
Dependencies & tags
Components used: container, container_proxy, freezable, health, locomotor, sleeper
Tags: Adds and checks many internal state tags (busy, idle, open, knockback, devoured, noelectrocute, nointerrupt, invisible, notalking, etc.) via sg:HasStateTag() and sg:GoToState().
Properties
No public properties. All state-specific data is stored in inst.sg.mem and inst.sg.statemem (state memory and per-state memory respectively).
Main functions
No top-level functions are exported by SGchester itself. It defines helper functions in the local scope and registers a StateGraph via return StateGraph("chester", states, events, "init"). The following local helper functions are key internal utilities:
ToggleOffPhysics(inst)
- Description: Disables physics collision for the entity by setting the ground-only collision mask and marks
isphysicstogglein state memory. - Parameters:
inst(Entity) — the Chester instance. - Returns: Nothing.
ToggleOnPhysics(inst)
- Description: Restores full physics collision mask (world, obstacles, characters, giants) and clears
isphysicstoggle. - Parameters:
inst(Entity) — the Chester instance. - Returns: Nothing.
ClearStatusAilments(inst)
- Description: Unfreezes the entity if it is currently frozen.
- Parameters:
inst(Entity) — the Chester instance. - Returns: Nothing.
SpawnMoveFx(inst, scale)
- Description: Spawns a random variation of
hutch_move_fxand ensures recent variations are not reused immediately (up toMAX_RECENT_FX). The effect scale is interpolated based onscale. - Parameters:
inst(Entity) — the Chester instance.scale(number) — scale factor betweenMIN_FX_SCALE(.5) andMAX_FX_SCALE(1.6).
- Returns: Nothing.
SetContainerCanBeOpened(inst, canbeopened)
- Description: Controls whether Chester can be interacted with as a container. When
canbeopenedis false, it closes any open containers (viacontainer:Close()orcontainer_proxy:Close()) and disables opening; when true, it enables opening. - Parameters:
inst(Entity) — the Chester instance.canbeopened(boolean) — whether to allow opening.
- Returns: Nothing.
Events & listeners
- Listens to:
"animover"— transition states (e.g., open→open_idle, close→idle)."animqueueover"— ends transition state."attacked"— triggershitorelectrocutestate, plays hurt sound."morph"— entersmorphstate with custom callback."knockback"— entersknockbacklandedstate."devoured"— entersdevouredstate."spitout"— exitsdevouredand triggersknockback."onstep","onsleep","onelectrocute","onlocomote","onhop","onsink","onfallinvoid","ondeath","oncorpsechomped"— viaCommonHandlers.
- Pushes:
"refreshcrafting"— when container closes."unfreeze","onwakeup"— via component interactions."knockback"— fromspitoutanddevouredexit.