Skip to main content

Precaching

Namespace: DeadworksManaged.Api

Resources (particles, models, heroes) must be precached during map load before they can be used at runtime.

When to Precache

Override OnPrecacheResources() in your plugin — it is called during map load:

public override void OnPrecacheResources()
{
Precache.AddResource("particles/upgrades/mystical_piano_hit.vpcf");
Precache.AddResource("particles/abilities/bull_drain.vpcf");
Precache.AddHero(Heroes.Inferno);
}

Important: All Precache methods must be called inside OnPrecacheResources(). Calling them at other times has no effect.

Precache Methods

MethodDescription
AddResource(string path)Precache a resource by path (particles, models, etc.)
AddHero(string name)Precache a hero by internal name (e.g. "hero_inferno")
AddHero(Heroes hero)Precache a hero by enum value
AddAllHeroes()Precache all heroes (for runtime hero/ability swapping)

Resource Paths

Resources use Valve's VPK path format:

// Particle effects
Precache.AddResource("particles/upgrades/mystical_piano_hit.vpcf");
Precache.AddResource("particles/abilities/bull_drain.vpcf");

// Models (if needed)
Precache.AddResource("models/props/my_model.vmdl");

Hero Precaching

If your plugin swaps heroes or abilities at runtime, you must precache them:

public override void OnPrecacheResources()
{
// Precache specific heroes
Precache.AddHero(Heroes.Inferno);
Precache.AddHero(Heroes.Wraith);

// Or precache ALL heroes (recommended for dynamic hero selection)
Precache.AddAllHeroes();
}

See Also

  • Plugin BaseOnPrecacheResources() lifecycle hook
  • Particles — Particle effects require precaching
  • Heroes — Hero precaching for dynamic selection