Sgpig
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGpig is a StateGraph definition that controls pig entity behavior through a collection of named states and transition events. It integrates with multiple components (combat, follower, health, sleeper, shadowparasitemanager) to manage transitions between idle, moving, attacking, eating, sleeping, dying, transforming (from Werepig), and reacting to environmental hazards (freezing, electrocution, void fall). The state machine also supports special actions like chop, cheer, win_yotb, and corpse handling.
Usage example
-- This stategraph is automatically applied by the prefab "werepig" and its variants.
-- To create a pig entity using this stategraph:
local inst = Prefab("werepig")
inst:AddTag("pig")
-- The stategraph is internally assigned by the prefab definition; no direct SGpig call is needed.
Dependencies & tags
Components used: combat, follower, health, sleeper, shadowparasitemanager
Tags: Adds busy, idle, chopping, attack, transform, sleeping, noelectrocute, hostile (conditionally removed during transformation)
Properties
No public properties defined in this stategraph file. State behavior is configured entirely via states table and event handlers.
Main functions
This file does not define any standalone functions. It returns a configured StateGraph instance. The primary "functions" are the state entries (State{} blocks) and event/action handlers.
State{name = ..., onenter = ..., events = ..., timeline = ..., onexit = ..., tags = ...}
- Description: Represents a behavior state in the state machine. Each state defines what happens when entering (
onenter), exiting (onexit), how time-based events (timeline) are processed, and which tag conditions control transitions (tags).eventsdefines which external or animation events trigger state changes. - Parameters:
name(string) — unique identifier for the state (e.g.,"idle","attack")onenter(function) — runs when the state becomes activeonexit(function) — runs when leaving the stateevents(table) — list ofEventHandlerentries mapping events to callbackstimeline(table) — list ofTimeEvententries for time-based triggerstags(table) — set of tags used by the stategraph for conditional transitions
- Returns: A
Stateobject added to thestatesarray.
Events & listeners
-
Listens to:
- Standard state handlers (
CommonHandlers.OnStep,OnLocomote,OnSleep,OnFreeze,OnElectrocute,OnAttack,OnAttacked,OnDeath,OnHop,OnSink,OnFallInVoid,OnIpecacPoop,OnCorpseChomped) "transformnormal"— triggers"transformNormal"state if not dead"doaction"— triggers"chop"state when action isACTIONS.CHOP"cheer"— triggers"cheer"state"win_yotb"— triggers"win_yotb"state"animover"— transitions back to"idle"after animations complete (in many states)
- Standard state handlers (
-
Pushes:
- None directly. Relies on the stategraph system to handle state transitions internally.