Bat
Based on game build 714014 | Last updated: 2026-03-04
Overview
The bat prefab represents a flying, hostile creature found in cave environments. It uses a custom brain (SGbat stategraph) and integrates with multiple components to handle locomotion, combat, teaming, sleep, and acid resistance. The bat can switch between solo and team-based aggression, share targets with nearby bats, and adapt its drop table, attack speed, speed, and damage output when infused with acid via the acidinfusible component.
Usage example
local bat = SpawnPrefab("bat")
bat.Transform:SetPosition(x, y, z)
bat.components.combat:SetTarget(target)
bat.components.locomotor.walkspeed = TUNING.BAT_WALK_SPEED * 1.5
Dependencies & tags
Components used: locomotor, sleeper, combat, health, lootdropper, inventory, periodicspawner, inspectable, knownlocations, teamattacker, acidinfusible, eater, burnable, freezeable, hauntable, childspawner, homeseeker
Tags added: cavedweller, monster, hostile, bat, scarytoprey, flying, ignorewalkableplatformdrowning
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
scrapbook_scale | number | 0.75 | Scale used for the scrapbook icon. |
_hometask | ScheduledTask or nil | nil | Task scheduled to send the bat home when it sleeps (daytime). |
teamattacker.inteam | boolean | false | Whether the bat is currently in a team. |
teamattacker.teamleader | Entity (via components.teamleader) or nil | nil | Reference to the bat's team leader. |
Main functions
Retarget(inst)
- Description: Finds a new valid target for the bat using distance and tag filters. If no target is in combat mode and the bat is not yet in a team, attempts to form a team with the new target.
- Parameters:
inst(Entity) — the bat instance. - Returns:
newtarget(Entity or nil) — the newly selected target, if any. - Error states: Does not error; returns
nilif no target is found or if the bat is in a team with a non-attacking leader.
KeepTarget(inst, target)
- Description: Determines whether the bat should retain its current target (e.g., during team-based coordination).
- Parameters:
inst(Entity),target(Entity or nil). - Returns:
trueif the bat should keep the target (when in a team but leader is not attacking, or when orders areORDERS.ATTACK); otherwisefalse.
OnInfuse(inst)
- Description: Activated when the bat is infused with acid. Modifies visual appearance (eye color/light), updates loot table, increases retarget frequency, enables nitre eating, and adds the
thiefcomponent. - Parameters:
inst(Entity). - Returns: Nothing.
OnUninfuse(inst)
- Description: Reverses the effects of acid infusion: resets visuals and loot table, slows retargeting, disables nitre eating, and removes the
thiefcomponent. - Parameters:
inst(Entity). - Returns: Nothing.
OnAttacked(inst, data)
- Description: Handles the bat being attacked. Attempts to form a team or alert existing teammates for support.
- Parameters:
inst(Entity) — the bat instance.data(table) — event data, must containattacker.
- Returns: Nothing.
- Error states: Early return if
data.attackerisnil.
OnIsDay(inst, isday)
- Description: Schedules or cancels a task to return home when it becomes day (bat sleep behavior).
- Parameters:
inst(Entity),isday(boolean) — current world time state. - Returns: Nothing.
BatSleepTest(inst, ...)
- Description: Custom sleep test that prevents sleeping while acid-infused.
- Parameters:
inst(Entity), plus additional arguments passed bysleeper. - Returns:
falseif infused; otherwise callsNocturnalSleepTest(inst, ...).
Events & listeners
- Listens to:
attacked— triggersOnAttackedto prompt teaming and sharing of targets. - Listens to:
enterlimboandexitlimbo— managed viaOnEntitySleepandOnEntityWaketo start/stop day-watching.
Notes
- The bat periodically spawns
guanoviaperiodicspawner(default intervals: 120–240 seconds). - Acid infusion modifies core combat behavior and adds utility (e.g., nitre eating, stealing). The
thiefcomponent is dynamically added/removed during infuse/uninfuse events. - Team coordination is supported via
teamattackerandteamleadercomponents; teams are shared across bats withinSHARE_TARGET_DIST(40 units), up toMAX_TARGET_SHARES(5).