SGpig
Based on game build 722832 | Last updated: 2026-04-21
Overview
SGpig is the stategraph that controls animation states and behavioral transitions for pig-type entities in Don't Starve Together. It manages standard actions like attacking, eating, and chopping, as well as special states for werepig transformation, follower loyalty behaviors, and death handling with shadow parasite revival support. This stategraph integrates with the combat, follower, health, sleeper, and shadowparasitemanager components to coordinate entity behavior.
Usage example
-- Attach the pig stategraph to a pig prefab entity
local inst = CreateEntity()
inst:AddComponent("health")
inst:AddComponent("combat")
inst:AddComponent("follower")
inst:AddComponent("sleeper")
-- Assign the stategraph
inst:SetStateGraph("SGpig")
-- Trigger state transitions via events
inst:PushEvent("transformnormal")
inst:PushEvent("cheer")
Dependencies & tags
External dependencies:
stategraphs/commonstates-- provides CommonHandlers and CommonStates helper functions for standard state definitions
Components used:
combat-- calls HasTarget(), StartAttack(), DoAttack() for combat statesfollower-- calls GetLeader(), GetLoyaltyPercent() for loyalty-based animationshealth-- calls IsDead() to check entity death stateleader-- calls IsRollCalling() via leader entity for roll call detectionsleeper-- calls GoToSleep() after werepig transformationshadowparasitemanager-- calls ReviveHosted() for parasite revival on death
Tags:
idle-- added to funnyidle statebusy-- added to death, abandon, transformNormal, attack, eat, hit, dropitem, cheer, win_yotb statestransform-- added to transformNormal statesleeping-- added to transformNormal statenoelectrocute-- added to transformNormal stateattack-- added to attack statechopping-- added to chop statehostile-- removed during transformNormal stateguard-- checked in funnyidle for angry animation
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
| None | No properties are defined. |
Main functions
StateGraph("pig", states, events, "init", actionhandlers)
- Description: Constructs and returns the pig stategraph with all defined states, event handlers, default init state, and action handlers. This is the return value of the file.
- Parameters:
states-- table of State definitions including custom and CommonStates-added statesevents-- table of EventHandler and CommonHandler definitions"init"-- default starting state nameactionhandlers-- table of ActionHandler mappings for player actions
- Returns: StateGraph instance assigned to pig-type entities
States
funnyidle
- Description: Default idle state with context-sensitive animations based on loyalty, time of day, combat status, and guard status.
- Tags:
idle - Transitions: On
animoverevent, returns toidlestate. - Behavior: Plays "oink" sound on enter. Animation varies: "hungry" if loyalty
<= 0.05and not roll-called, "idle_angry" if guard or has combat target, "idle_scared" at night, "idle_happy" if loyalty> 0.3or roll-called, otherwise "idle_creepy".
death
- Description: Handles death animation and loot dropping, with shadow parasite revival support.
- Tags:
busy - Transitions: On
animover, either callsReviveHosted()if parasite-hosted or transitions tocorpsestate. - Behavior: Plays grunt sound and death animation. Removes physics colliders and drops loot unless shadow parasite revival is pending.
abandon
- Description: Plays abandonment animation when follower relationship ends.
- Tags:
busy - Parameters:
leader-- the leader entity to face during animation - Transitions: On
animover, returns toidlestate. - Behavior: Stops physics, plays "abandon" animation, faces leader position if leader is valid.
transformNormal
- Description: Handles werepig-to-pig transformation with symbol overrides and post-transform sleep.
- Tags:
transform,busy,sleeping,noelectrocute - Transitions: On
animover, callsGoToSleep(15-19 seconds)and transitions tosleepingstate. - Behavior: Plays transformation sound, switches to werepig_build, plays transform animation, removes
hostiletag, overrides pig body symbols. On exit, restores original build and clears symbol overrides.
attack
- Description: Standard attack animation with combat component integration.
- Tags:
attack,busy - Transitions: On
animover, returns toidlestate. - Behavior: Plays attack and whoosh sounds, calls
StartAttack(), stops physics, plays "atk" animation. At frame 13, callsDoAttack()and removesattackandbusytags.
chop
- Description: Tree chopping action state.
- Tags:
chopping - Transitions: On
animover, returns toidlestate. - Behavior: Stops physics, plays "atk" animation. At frame 13, performs buffered action.
eat
- Description: Eating animation with sound effects.
- Tags:
busy - Transitions: On
animover, returns toidlestate. - Behavior: Stops physics, plays "eat" animation. Performs buffered action at frame 10. Plays eat sound at frame 2, chew sounds at frames 11 and 21.
hit
- Description: Hit reaction state when attacked.
- Tags:
busy - Transitions: On
animover, returns toidlestate. - Behavior: Plays oink sound and hit animation, stops physics, updates hit recovery delay.
dropitem
- Description: Item dropping/pickup animation state.
- Tags:
busy - Transitions: On
animover, returns toidlestate. - Behavior: Stops physics, plays "pig_pickup" animation. Performs buffered action at frame 10.
cheer
- Description: Cheer/buff animation state.
- Tags:
busy - Transitions: On
animover, returns toidlestate. - Behavior: Stops physics, plays "buff" animation.
win_yotb
- Description: Year of the Beast victory animation state.
- Tags:
busy - Transitions: On
animover, returns toidlestate. - Behavior: Stops physics, plays "win" animation.
CommonStates-added states
- Description: Additional states added via CommonStates helper functions.
- States included:
walk/run-- locomotion states with footstep soundssleep-- sleeping state with snore sound at frame 35idle-- default idle (mapped to funnyidle)refuse-- rejection animation ("pig_reject")frozen-- freeze reaction stateselectrocute-- electrocution reaction statespickup-- item pickup action (10 frames)gohome-- go home action (4 frames)hop-- boat jump states (pre, loop, post)sink/washashore-- water interaction statesvoidfall-- falling into void stateipecacpoop-- ipecac poison reactionparasiterevive-- shadow parasite revival statecorpse-- corpse/chomped states
Events & listeners
Listens to:
transformnormal-- transitions to transformNormal state if not deaddoaction-- transitions to chop state if action is CHOP and not busy/deadcheer-- transitions to cheer state if not busy/deadwin_yotb-- transitions to win_yotb state if not busy/deadanimover-- returns to idle state from most action states- CommonHandlers:
OnStep,OnLocomote,OnSleep,OnFreeze,OnElectrocute,OnAttack,OnAttacked,OnDeath,OnHop,OnSink,OnFallInVoid,OnIpecacPoop,OnCorpseChomped
Pushes: None identified
Action handlers
| Action | State |
|---|---|
ACTIONS.GOHOME | gohome |
ACTIONS.EAT | eat |
ACTIONS.CHOP | chop |
ACTIONS.PICKUP | pickup |
ACTIONS.EQUIP | pickup |
ACTIONS.ADDFUEL | pickup |
ACTIONS.TAKEITEM | pickup |
ACTIONS.UNPIN | pickup |
ACTIONS.DROP | dropitem |
ACTIONS.MARK | dropitem |