Entity index: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with 'An '''entity index''' is a unique integer given to every entity by the engine. It allows the same entity to be referred to across DLL boundaries. [[Entity limit|There can be…')
 
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
An '''entity index''' is a unique [[integer]] given to every entity by the engine. It allows the same entity to be referred to across DLL boundaries.
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, [[pointer]]s to <code>[[CBaseEntity]]</code> are more useful.


[[Entity limit|There can be up to 4096 entities in the index]]. The first 2048 entries are reserved for entities with [[edict]]s, which cross the client/server divide.
[[Entity limit|There can be up to 4096 entities in the index]]. The first 2048 entries are reserved for entities with [[edict]]s, which cross the client/server divide.
{{tip|[[Worldspawn]] is always entity 0, while indices 1 to <[[maxplayers]]> are reserved for players.}}
{{tip|Use {{command|ent_text}} command to find out what index specific entities have. It's displayed in round brackets.}}


{{note|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 <code>[[CHandle]]</code> for long-term storage.}}
{{note|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 <code>[[CHandle]]</code> for long-term storage.}}
Line 7: Line 10:
== Usage ==
== Usage ==


To get an entity's index, call <code>entindex()</code>. When programming mods this is only useful for comparison with another entity index: most of the time a [[pointer]] can be used instead.
; Shared
: <code>[[int]] [[CBaseEntity]]::entindex()</code>
; Server
: <code>[[edict_t]]* INDEXENT( int iEdictNum )</code>
: <code>int ENTINDEX( edict_t* pEdict )</code>
: <code>[[CEntInfo]]* [[gEntList]].GetEntInfoPtrByIndex(int)</code>
: ''Functions below are not available in Alien Swarm:''
: <code>int [[IVEngineServer|engine]]->IndexOfEdict([[edict_t]])</code>
: <code>[[edict_t]] engine->PEntityOfEntIndex(int)</code> (networked ents only)
; Client
: <code>[[C_BaseEntity]] ClientEntityList().GetBaseEntity(int)</code>


== See also ==
== See also ==
Line 13: Line 26:
* [[Edict]]
* [[Edict]]
* [[Entity limit]]
* [[Entity limit]]
* [[ent_text]]


[[Category:Programming]]
[[Category:Programming]]

Latest revision as of 05:06, 9 September 2024

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.
Tip.pngTip:Use ent_text command to find out what index specific entities have. It's displayed in round brackets.
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
edict_t* INDEXENT( int iEdictNum )
int ENTINDEX( edict_t* pEdict )
CEntInfo* gEntList.GetEntInfoPtrByIndex(int)
Functions below are not available in Alien Swarm:
int engine->IndexOfEdict(edict_t)
edict_t engine->PEntityOfEntIndex(int) (networked ents only)
Client
C_BaseEntity ClientEntityList().GetBaseEntity(int)

See also