Sgoceanfish
Based on game build 714014 | Last updated: 2026-03-08
Overview
SGoceanfish is the stategraph for ocean fish prefabs (e.g., ocean fish that can be fished or attacked by players). It orchestrates transitions between states such as idle, breach, eat, bitehook_loop, and shoot, enabling the entity to respond to player actions (e.g., eating, fishing, fire suppression). It integrates closely with the locomotor, firedetector, oceanfishable, and oceanfishingrod components to control physics, animation, and behavior synchronization during interactions.
Usage example
This stategraph is automatically assigned to ocean fish prefabs (e.g., oceanfish, oceanfish_spawning) at construction time. It is not meant to be added manually; however, a typical modder might extend it by adding new states or modifying its action handlers and event callbacks:
-- Example: Check if a fish is currently in the 'breach' state
if fish.inst.sg.currentstate.name == "breach" then
print("Fish is breaching!")
end
Dependencies & tags
Components used: locomotor, firedetector, oceanfishable, oceanfishingrod
Tags handled internally: busy, idle, canrotate, jumping, shooting, partiallyhooked (added/removed via inst:AddTag()/RemoveTag() elsewhere)
Tags checked: oceantrawler, partiallyhooked
Properties
No public properties are defined in this stategraph file.
Main functions
This is a StateGraph definition (returned from return StateGraph(...)), not a component with traditional methods. The "main functions" are the state callbacks:
State callbacks (by name)
- Description: These are per-state functions (
onenter,onexit,onupdate,ontimeout,timeline,events) embedded in thestatesarray. Each defines behavior during specific phases of the fish's animation/behavior cycle. - Parameters: State callbacks receive
(inst, data?)whereinstis the entity instance anddatamay contain action or event payload (e.g.,{ fire_pos = ... }). - Returns: None — these are event-driven handlers.
- Error states: N/A — invalid state transitions are prevented by state tags and conditional
GoToStateguards.
SpawnSplashFx(inst)
- Description: Spawns a random breach/fish splash FX prefab if defined in
inst.fish_def.breach_fx, provided the fish is not under a boat. - Parameters:
inst(entity instance) — the fish entity. - Returns: Nothing.
- Error states: No FX is spawned if
breach_fxisnilorinst.sg.statemem.underboatis true.
IsUnderBoat(inst)
- Description: Detects if the fish is positioned under a platform (e.g., a boat) using the world map API.
- Parameters:
inst(entity instance) — the fish entity. - Returns:
trueif under a platform,falseotherwise. - Error states: None.
SetBreaching(inst, is_in_air)
- Description: Switches the fish's animation layer and facing mode depending on whether it is in the air (
breaching) or submerged. - Parameters:
inst(entity instance);is_in_air(boolean). - Returns: Nothing.
- Error states: None.
Events & listeners
-
Listens to:
locomote— viaCommonHandlers.OnLocomote(true, true)(fromcommonstates.lua)dobreach— triggersbreachstate unless jumping orfood_targetis a trawlerdoleave— triggersleavestate unless busy or jumpingoceanfishing_stoppedfishing— triggersbreachon rod removal unless leaving or jumpingputoutfire— triggersshootstate (with fire position) unless jumping or busy
-
Pushes: This stategraph itself does not push events — it responds to them. However, entity behavior is coordinated through events fired by the state graph (e.g., via
PerformBufferedAction(),PushEvent("animover")in timelines).