PrecacheModel

From Valve Developer Community
Jump to: navigation, search
English (en)Translate (Translate)

PrecacheModel is a function provided to precache models or materials by string.

Usage

//-----------------------------------------------------------------------------
// Purpose: Add model to level precache list
// Input  : *name - model name
// Output : int -- model index for model
//-----------------------------------------------------------------------------
int CBaseEntity::PrecacheModel( const char *name )


Examples

#define PROP_COMBINE_BALL_MODEL	"models/effects/combineball.mdl"
#define PROP_COMBINE_BALL_SPRITE_TRAIL "sprites/combineball_trail_black_1.vmt" 
//-----------------------------------------------------------------------------
// Precache 
//-----------------------------------------------------------------------------
void MyEntity::Precache( void )
{
	BaseClass::Precache( );
	PrecacheModel( PROP_COMBINE_BALL_MODEL );
	PrecacheModel( PROP_COMBINE_BALL_SPRITE_TRAIL );
}
//This example loops through an array of possible models
//And precaches each one.
void CSDKPlayer::Precache()
{

	int i = 0;
	while( pszPossiblePlayerModels[i] != NULL )
	{
		PrecacheModel( pszPossiblePlayerModels[i] );
		i++;
	}	

	BaseClass::Precache();
}