Entity index: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 10: Line 10:


; Shared
; Shared
: <code>[[int]] CBaseEntity::entindex()</code>
: <code>[[int]] [[CBaseEntity]]::entindex()</code>
; Server
; Server
: <code>[[CEntInfo]] [[gEntList]].GetEntInfoPtrByIndex(int)</code>
: <code>int [[IVEngineServer|engine]]->IndexOfEdict([[edict_t]])</code>
: <code>int [[IVEngineServer|engine]]->IndexOfEdict([[edict_t]])</code>
: <code>edict_t engine->PEntityOfEntIndex(int)</code>
: <code>[[edict_t]] engine->PEntityOfEntIndex(int)</code> (networked ents only)
: <code>[[CEntInfo]] gEntList.GetEntInfoPtrByIndex(int)</code>
; Client
; Client
: <code>[[C_BaseEntity]] ClientEntityList().GetBaseEntity(int)</code>
: <code>[[C_BaseEntity]] ClientEntityList().GetBaseEntity(int)</code>

Revision as of 06:25, 4 April 2011

An entity index is a unique integer given to every entity by the engine. It allows the same entity to be referred to across library boundaries, but will be different on the client and server unless an edict is used. Within the client and server, pointers to CBaseEntity are more useful.

There can be up to 4096 entities in the index. The first 2048 entries are reserved for entities with edicts, which cross the client/server divide.

Tip.pngTip:Worldspawn is always entity 0, while indices 1 to <maxplayers> are reserved for players.
Note.pngNote:An entity index is not reliable between frames, as it can be freed from one entity and and reallocated to another at any time. Use CHandle for long-term storage.

Usage

Shared
int CBaseEntity::entindex()
Server
CEntInfo gEntList.GetEntInfoPtrByIndex(int)
int engine->IndexOfEdict(edict_t)
edict_t engine->PEntityOfEntIndex(int) (networked ents only)
Client
C_BaseEntity ClientEntityList().GetBaseEntity(int)
Confirm:An existing entity's index cannot be changed.

See also