Mossling
Based on game build 714014 | Last updated: 2026-03-06
Overview
The mossling prefab defines a seasonal creature that appears during spring and summer (and summer in the Caves). It is part of a herd (Moose egg herd), uses herd-based AI via herdmember, and engages in combat when attacked. The entity has a built-in lifecycle tied to seasonal changes—when spring ends or it enters the Caves, it marks itself for removal. It supports networked persistence via custom save/load handlers and integrates with DST’s combat, health, sound, and anim systems.
Usage example
The Mossling prefab is not typically instantiated manually; it is spawned by world generation (e.g., during Moose egg hatching). A modder might reference its components like so:
-- Example: checking if a Mossling is currently under a guardian's protection
if inst.components.herdmember.herd ~= nil then
local has_guardian = inst.components.herdmember.herd.components.guardian:HasGuardian()
end
-- Example: modifying Mossling walk speed dynamically
inst.components.locomotor.walkspeed = TUNING.MOSSLING_WALK_SPEED * 1.5
Dependencies & tags
Components used: health, combat, sizetweener, sleeper, lootdropper, inspectable, knownlocations, inventory, herdmember, eater, burnable, locomotor.
Tags added: mossling, animal, herdmember.
Tags checked: prey, smallcreature, monster, player, moose (via RETARGET_CANT_TAGS, RETARGET_ONEOF_TAGS in RetargetFn).
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
mother_dead | boolean | false | Tracks whether the Mossling’s mother (e.g., the spawning entity) is dead; affects retargeting logic. |
shouldGoAway | boolean | false | Set to true when season changes or in caves; triggers removal during sleep. |
Main functions
HasGuardian(inst)
- Description: Helper function that returns
trueif the Mossling belongs to a herd with an active guardian. Used to conditionally adjust behavior (e.g., target retention). - Parameters:
inst(Entity) — the Mossling instance. - Returns:
boolean—trueif the herd has a guardian, otherwisefalse.
RetargetFn(inst)
- Description: Entity-targeting function for the
combatcomponent. Determines whether the Mossling can find a valid new target. Only activates ifmother_deadistrueor the Mossling is no longer under a guardian’s protection. UsesFindEntityto locate a nearby valid target. - Parameters:
inst(Entity) — the Mossling instance. - Returns:
Entity?— the first valid target found, ornil. - Error states: Returns
nilif no valid target exists within range (TARGET_DIST = 6), or if all candidate entities are tagged with forbidden tags (prey,smallcreature,mossling,moose) or do not match required tags (monster,player).
KeepTargetFn(inst, target)
- Description: Validation function for retaining an existing target. Allows target retention unless the Mossling is under a guardian and the target is very close (within
LOSE_TARGET_DIST = 13), in which case it drops the target. - Parameters:
inst(Entity) — the Mossling instance.target(Entity) — the candidate target.
- Returns:
boolean—trueif the target should be kept, otherwisefalse.
OnAttacked(inst, data)
- Description: Event handler for the
attackedevent. Assigns the attacker as the current target and attempts to share the target with up to 60 allies (other Mosslings or the guardian). - Parameters:
inst(Entity) — the Mossling instance.data(table) — event payload, must includeattacker(Entity).
- Returns: Nothing.
- Note: Calls
combat:SetTarget(data.attacker)andcombat:ShareTarget(...)with a custom filter function that includes other Mosslings and the herd guardian.
OnSave(inst, data)
- Description: Saves persistent state before the game is closed. Stores
mother_deadandshouldGoAwayflags. - Parameters:
inst(Entity) — the Mossling instance.data(table) — the save table to populate.
- Returns: Nothing.
OnLoad(inst, data)
- Description: Restores state after loading. Applies previously saved
mother_deadandshouldGoAwayflags if present. - Parameters:
inst(Entity) — the Mossling instance.data(table) — the loaded save data.
- Returns: Nothing.
OnEntitySleep(inst)
- Description: Handles removal of the Mossling during sleep when
shouldGoAwayistrue. Called automatically by the game state graph during the sleep transition. - Parameters:
inst(Entity) — the Mossling instance. - Returns: Nothing.
- Note: Calls
inst:Remove()ifinst.shouldGoAwayistrue.
OnSpringChange(inst, isspring)
- Description: Reacts to seasonal changes (spring/summer flag). Sets
shouldGoAway = trueif it is not spring/summer or if the world has the"cave"tag. Triggers immediate removal if the entity is already sleeping. - Parameters:
inst(Entity) — the Mossling instance.isspring(boolean) — whether the current season is spring/summer.
- Returns: Nothing.
Events & listeners
- Listens to:
attacked— triggersOnAttackedto set or share targets.entitysleep— triggersOnEntitySleepto remove the entity ifshouldGoAway.
- Pushes: None (uses standard game events for save/load, health, and combat).