Skip to main content

Sanitybadge

Based on game build 714014 | Last updated: 2026-03-08

Overview

SanityBadge is a UI widget component that visually represents a player's sanity or lunacy level using animated symbols and directional arrows. It inherits from Badge, integrates with the sanity replica component, and dynamically switches appearance and animations based on the current sanity mode (SANITY_MODE_INSANITY or SANITY_MODE_LUNACY). It also handles visual feedback for sanity change rate, penalty overlays, ghost drain, and transitions between modes.

Usage example

local badge = AddChildWidget(owner, "sanitybadge")
badge.owner = some_entity_with_sanity_replica
badge:StartUpdating()
badge:SetPercent(80, 100, 0) -- val, max, penalty
badge:PulseGreen() -- or PulseRed()

Dependencies & tags

Components used: None identified
Tags: Checks sleeping on owner; no tags added or removed.

Properties

PropertyTypeDefault ValueDescription
sanitymodeSANITY_MODE_...SANITY_MODE_INSANITYCurrent sanity mode (insanity or lunacy), used to select visual style.
val, maxnumber100, 100Current and maximum sanity/lunacy values.
penaltypercentnumber0Fraction (0–1) of penalty overlay to display.
ghostbooleanfalseWhether ghost drain is active.
arrowdirstringnilCurrent animation state of the sanity rate arrow.
transition_taskTasknilDelayed task for mode transition completion.
topperanimUIAnimOverlay animation for penalty indicator (e.g., crack effect).
circleframe2UIAnimAnimated circle frame for sanity/lunacy transitions.
sanityarrowUIAnimDirectional arrow anim showing sanity change direction/rate.
ghostanimUIAnimAnim for ghost drain visual effect.

Main functions

DoTransition()

  • Description: Switches visual assets between sanity and lunacy modes (e.g., background, icon, colors) and refreshes the percentage animation.
  • Parameters: None.
  • Returns: Nothing.
  • **Error states:**none.

SetPercent(val, max, penaltypercent)

  • Description: Updates the displayed sanity/lunacy value, penalty overlay, and initiates transition animations if the mode changed.
  • Parameters:
    val (number) — Current sanity/lunacy amount.
    max (number) — Maximum sanity/lunacy amount.
    penaltypercent (number, optional) — Penalty overlay amount (0–1). Defaults to 0.
  • Returns: Nothing.
  • **Error states:**none.

SpawnTransitionFX(anim)

  • Description: Spawns a temporary UI animation effect at the badge's position during mode transitions.
  • Parameters:
    anim (string) — Name of the animation to play ("transition_sanity" or "transition_lunacy").
  • Returns: Nothing.
  • Error states: If self.parent is nil, no FX is spawned.

PulseGreen()

  • Description: Triggers a green pulse animation if in sanity mode; otherwise (lunacy mode), triggers a red pulse.
  • Parameters: None.
  • Returns: Nothing.
  • **Error states:**none.

PulseRed()

  • Description: Triggers a red pulse animation if in sanity mode; otherwise (lunacy mode), triggers a green pulse.
  • Parameters: None.
  • Returns: Nothing.
  • **Error states:**none.

OnUpdate(dt)

  • Description: Updates the sanity arrow direction and ghost drain animation based on the owner's sanity replica data. Skipped if the server is paused.
  • Parameters:
    dt (number) — Time since last frame.
  • Returns: Nothing.
  • **Error states:**none.

Events & listeners

  • Listens to:
    animover (on ghostanim.inst) — Triggers OnGhostDeactivated, which hides the ghost animation after deactivation completes.
    animover (on FX UIAnim) — Triggers RemoveFX, which removes the temporary FX widget after animation completes.
  • Pushes: None.