PrecacheModel

From Valve Developer Community
Revision as of 22:57, 9 April 2011 by LordNed (talk | contribs) (Created Page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

PrecacheModel is a function provided to Precache models by string. It is generally used to Precache assets used by an entity.


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();
}