Precaching Assets

From Valve Developer Community
Revision as of 09:38, 8 April 2005 by Erik Johnson (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Precache()

The Precache() function is available to all descendants of the CBaseEntity class and must be called in the Spawn() function of each entity. All assets used by the entity (models, sounds, VCD, decals) must be declared in this function to be used. Assets may not be precached outside of this function.

Assets are precached using the following functions:

PrecacheModel()
Used to precache a model.
int CBaseEntity::PrecacheModel(
     const char *name
)

Parameters

  • name
    • Filename of the model to load

Return Value

  • Reference index for the model.
PrecacheScriptSound()
Used to precache a sound script as declared in a sound script file.
void CBaseEntity::PrecacheScriptSound(
     const char *soundname
)

Parameters

  • soundname
    • Name of sound script to precache.

Remarks

  • Sound script must be declared in the sound script manifest document.

Return Value

  • None.
PrecacheInstancedScene()
Used to precache a VCD file.
void PrecacheInstancedScene(
     char const *pszScene
)

Parameters

  • pszScene
    • Filename of the VCD to precache.

Return Value

  • None.
UTIL_PrecacheOther()
Utility function that will call the Precache() function for an entity that will be referenced or created during the lifetime of the calling entity. This is often used for weapons that will create a child entity (like a grenade) dynamically during the course of a session.
void UTIL_PrecacheOther(
     const char *szClassname,
     const char *modelName
)

Parameters

  • szClassname
    • Entity classname to precache assets for.
  • modelName
    • Model name to use for this entity.

Return Value

  • None.
UTIL_PrecacheDecal()
Used to precache a decal.
int UTIL_PrecacheDecal(
     const char *name,
     bool preload
)

Parameters

  • name
    • Name of the decal to precache.
  • preload
    • Whether or not to preload this decal.

Return Value

  • Reference index for the decal model.