Flies
Based on game build 714014 | Last updated: 2026-03-05
Overview
The flies prefab is a lightweight decorative entity that simulates a swarm of flies. It uses the playerprox component to detect when a player is near or far and responds by switching between animation states and playing or stopping sound effects accordingly. It is commonly used in world generation to enhance environmental immersion (e.g., near swamps, caves, or decayed structures). The prefab is non-interactive (NOCLICK, DECOR tags) and runs pristinely on clients, with logic executed only on the master simulation.
Usage example
-- Example: Spawn a flies entity at a specific world position
local inst = SpawnPrefab("flies")
if inst then
inst.Transform:SetPosition(x, y, z)
end
Dependencies & tags
Components used: playerprox, transform, animstate, soundemitter, network
Tags: Adds NOCLICK and DECOR unconditionally.
Properties
No public properties.
Main functions
onnear(inst)
- Description: Called when a player moves within the near distance (
2units). Stops the ambient fly looping sound and switches to a "post-swarm" animation (swarm_pst). - Parameters:
inst(Entity) — the flies entity instance. - Returns: Nothing.
onfar(inst)
- Description: Called when a player moves beyond the far distance (
3units). Plays the ambient fly sound (dontstarve/common/flies) and initiates the swarm animation sequence: firstswarm_pre, then loopingswarm_loop. - Parameters:
inst(Entity) — the flies entity instance. - Returns: Nothing.
OnWake(inst)
- Description: Event handler invoked when the entity wakes from sleep. Restarts the ambient sound if no player is close at the time of waking.
- Parameters:
inst(Entity). - Returns: Nothing.
OnSleep(inst)
- Description: Event handler invoked when the entity goes to sleep. Immediately kills the "flies" sound.
- Parameters:
inst(Entity). - Returns: Nothing.
oninit(inst)
- Description: Initialization callback. Forces an immediate update of the
playerproxcomponent to ensure correct initial state, then triggers eitherOnWakeor nothing depending on sleep state. AttachesOnEntityWakeandOnEntitySleephandlers. - Parameters:
inst(Entity). - Returns: Nothing.
Events & listeners
- Listens to:
OnEntityWake,OnEntitySleep— entity-level callbacks triggered by world sleep/wake state changes. - Pushes: None identified.