Skip to content

VFXManager ​

Inherits: Node

Centralized VFX system with pooling, shader precompilation, and support for multiple effect types (scene-based, telegraphs, materials).

Description ​

POOLING SYSTEM: Pre-instantiates all VFX during initialization and reuses from pools for zero-cost playback. Eliminates shader compilation hitches by compiling shaders during loading screen.

VFX TYPES:

  • Scene VFX: Pre-built effects (oneshot, loop, beam, path) from DatabaseVFX
  • Telegraph VFX: Runtime-created ground indicators and area markers
  • Material VFX: Shader-based entity effects (dissolve, outline, tint, etc.)

INITIALIZATION: Call initialize(system_hub) during game setup. This:

  1. Preloads all VFX from database

  2. Compiles shaders by temporarily adding to scene tree

  3. Returns instances to pools ready for instant playback

USAGE:

  • play_vfx_from_selection(selection, target, timer) - Main API for all VFX types
  • VFXSelection determines type, location, attachment, and parameters
  • stop_vfx(vfx) / stop_vfx_array(array) - Manual cleanup if needed
  • VFX automatically return to pool when finished

HANDS VFX: Special support for dual hand VFX - automatically creates and manages left/right pairs attached to entity hand bones.

TRACKING:

  • active_vfx: Currently playing scene-based VFX
  • active_material_effects: Currently active material effects on entities

Variables ​

Array[VFX]active_vfx[]
Array[VFXMaterial]active_material_effects[]
Node3Dvfx_container
Dictionaryvfx_pools{} # "type/name" -> Array[VFX]
inttotal_pooled0
boolis_initializedfalse

Methods ​

voidinitialize( system_hub: GameHost.SystemHub )
voidpreload_all_vfx( system_hub: GameHost.SystemHub )
Array[VFX]play_vfx_from_selection( selection: VFXSelection, target: Variant = null, timer: Timer = null )
VFXMaterialapply_material( material_sel: VFXSelectionMaterial, target: Variant, timer: Timer = null, item: Object = null )
voidstop_material_effects_on_entity( entity: Entity )
voidstop_material_effect( material_effect: VFXMaterial )
Array[VFXMaterial]get_material_effects_for_entity( entity: Entity )
boolentity_has_material_effect( entity: Entity, target: VFXSelectionMaterial.MaterialTarget )
intget_active_material_effect_count()
voidstop_vfx( vfx: VFX )
voidstop_vfx_array( vfx_array: Array )
voidcleanup_everything()

Constants ​

  • int MAX_POOL_SIZE = 500 - The most effects the pool keeps.

Variable descriptions ​

Array[VFX] active_vfx = [] ​

========== VFX TRACKING ==========

Array[VFXMaterial] active_material_effects = [] ​

The material effects on entities now.

Node3D vfx_container ​

The node the effects are placed under.

Dictionary vfx_pools = # "type/name" -> Array[VFX] ​

========== POOLING ==========

int total_pooled = 0 ​

How many effects wait in the pool.

bool is_initialized = false ​

========== INITIALIZATION ==========

Method descriptions ​

void initialize( system_hub: GameHost.SystemHub ) ​

Sets the manager up with the hub of the game systems.

void preload_all_vfx( system_hub: GameHost.SystemHub ) ​

Preload ALL VFX during loading screen and report memory usage

Array[VFX] play_vfx_from_selection( selection: VFXSelection, target: Variant = null, timer: Timer = null ) ​

Starts the effect of a selection on a target. Gives the effects made.

VFXMaterial apply_material( material_sel: VFXSelectionMaterial, target: Variant, timer: Timer = null, item: Object = null ) ​

Puts a material effect on an entity and gives it back (null when it could not go on): it lasts until its timer ends, the entity dies, or stop_material_effect. item: the enchanted item, for a selection that targets the item's own weapon.

void stop_material_effects_on_entity( entity: Entity ) ​

Stop all material effects on a specific entity

void stop_material_effect( material_effect: VFXMaterial ) ​

Stop a specific material effect

Array[VFXMaterial] get_material_effects_for_entity( entity: Entity ) ​

Get all active material effects for an entity

bool entity_has_material_effect( entity: Entity, target: VFXSelectionMaterial.MaterialTarget ) ​

Check if entity has material effect with specific target

int get_active_material_effect_count() ​

Get material effect count for debugging

void stop_vfx( vfx: VFX ) ​

Stops one effect.

void stop_vfx_array( vfx_array: Array ) ​

Stops a list of effects.

void cleanup_everything() ​

Stops every effect and empties the pool.