SpawnFader
Based on game build 722832 | Last updated: 2026-04-28
Overview
SpawnFader manages smooth visibility transitions for entities by animating the AnimState colour multiplier from transparent to opaque (fade in) or opaque to transparent (fade out). It uses netvars to synchronize fade state between master and clients, with dirty event listeners handling client-side updates. The component adds the NOCLICK tag during fading to prevent player interaction, and pushes completion events when the fade finishes.
Usage example
local inst = CreateEntity()
inst:AddComponent("spawnfader")
-- Fade in (entity becomes visible)
inst.components.spawnfader:FadeIn()
-- Fade out (entity becomes invisible)
inst.components.spawnfader:FadeOut()
-- Cancel ongoing fade
inst.components.spawnfader:Cancel()
Dependencies & tags
Components used:
AnimState-- applies colour multiplication for fade effect viaOverrideMultColourTags:NOCLICK-- added when fading starts, removed on master when fade-in completes
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
inst | entity | --- | The owning entity instance. |
_fade | net_tinybyte | --- | Fade progress value (0-7 scale). Dirty event: fadedirty. Synced to clients. |
_fadeout | net_bool | --- | Direction flag: true = fading out, false = fading in. |
fadeval | number | 0 | Current fade progress (0 to 1). Used for animation interpolation. |
updating | boolean | false | Whether the component is currently running its update loop. |
Main functions
FadeIn()
- Description: Starts a fade-in animation, making the entity gradually visible. Sets fade direction to inward and initiates the update loop.
- Parameters: None
- Returns: nil
- Error states: Errors if
self.inst.AnimStateis nil whenOnUpdatecallsOverrideMultColour(no nil guard present).
FadeOut()
- Description: Starts a fade-out animation, making the entity gradually invisible. Sets fade direction to outward and initiates the update loop.
- Parameters: None
- Returns: nil
- Error states: Errors if
self.inst.AnimStateis nil whenOnUpdatecallsOverrideMultColour(no nil guard present).
Cancel()
- Description: Cancels any ongoing fade animation. Resets
fadevalto 0 and triggers an immediate update to apply the cancellation. - Parameters: None
- Returns: nil
- Error states: Errors if
self.inst.AnimStateis nil (no nil guard inOnUpdatecalled byCancel).
OnUpdate(dt)
- Description: Update loop. Decrements
fadevalbydteach frame and applies colour multiplication to the entity'sAnimState. Behavior depends on_fadeoutdirection: fading out uses inverse quadratic interpolation (k = 1 - k*k) and pushesspawnfaderoutevent; fading in uses quadratic interpolation (k = 1 - fadeval*fadeval), pushesspawnfaderinevent, and removesNOCLICKtag on master when complete. Whenfadevalreaches 0, stops updating. - Parameters:
dt-- number, delta time in frames
- Returns: nil
- Error states: Errors if
self.inst.AnimStateis nil — callsOverrideMultColourwithout nil guard. Errors ifself.inst.highlightchildrenexists but contains entities withoutAnimStatecomponent.
OnRemoveFromEntity()
- Description: Cleanup handler called when component is removed from entity. Removes event listeners on client to prevent dangling callbacks.
- Parameters: None
- Returns: nil
- Error states: None
OnFadeDirty(inst) (local)
- Description: Property watcher callback. Fires when
_fadenetvar changes on client. Converts netvar value (0-7 scale) tofadeval(0-1 scale) and starts the update loop if not already updating. - Parameters:
inst-- entity instance
- Returns: nil
- Error states: None
OnDeath(inst) (local)
- Description: Event listener callback. Fires when entity dies. Cancels any ongoing fade animation to prevent orphaned update loops.
- Parameters:
inst-- entity instance
- Returns: nil
- Error states: None
Events & listeners
- Listens to:
fadedirty(client only) — triggersOnFadeDirty; syncs fade value from masterdeath(client only) — triggersOnDeath; cancels ongoing fade
- Pushes:
spawnfaderout— fired when fade-out animation completes (fadevalreaches 0 while fading out). Data: nonespawnfaderin— fired when fade-in animation completes (fadevalreaches 0 while fading in). Data: none