Skip to main content

Despawnfader

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

Overview​

DespawnFader handles the visual fading-out of an entity and ensures its removal after the fade completes. It supports both master and client simulation, synchronizing the fade progress across the network via net_tinybyte. When activated (e.g., via FadeOut()), the entity's opacity fades linearly over time, and the entity is either removed on the master or ceases updating on clients once faded.

Usage example​

local inst = CreateEntity()
inst:AddComponent("despawnfader")
inst.components.despawnfader:FadeOut()
-- The entity will fade out visually and be removed after ~1 second

Dependencies & tags​

Components used: AnimState, persists, replica.despawnfader._fade Tags: Adds NOCLICK during fading; removes the entity entirely when fade completes.

Properties​

PropertyTypeDefault ValueDescription
fadevalnumber0Current fade progress, ranging from 1 (fully opaque) to 0 (fully transparent).
updatingbooleanfalseWhether the component is currently being updated via StartUpdatingComponent.
_fadenet_tinybytenet_tinybyte(inst.GUID, ...)Networked value representing fade progress, synced as an integer scaled by 7.

Main functions​

FadeOut()​

  • Description: Initiates the fade-out sequence: sets fade progress to full, starts updates, disables click interaction, and disables persistence.
  • Parameters: None.
  • Returns: Nothing.
  • Error states: No-op if already fading (i.e., updating is true); otherwise begins the fade and transition.

OnUpdate(dt)​

  • Description: Runs each frame during fading; updates opacity based on fadeval, syncs progress on master, and removes the entity when fade completes.
  • Parameters: dt (number) — Delta time in seconds since last frame.
  • Returns: Nothing.
  • Error states: On clients, stops updating when fadeval <= 0; on master, removes the entity instance.

OnRemoveFromEntity()​

  • Description: Cleans up event listeners on the client side when the component is removed.
  • Parameters: None.
  • Returns: Nothing.

Events & listeners​

  • Listens to: fadedirty — triggers manual recalculation of fadeval on clients when the networked value changes (via _fade update).
  • Pushes: None.