EHANDLE: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (taken data from networking_entities linked back to it)
 
(made redir)
 
(19 intermediate revisions by 9 users not shown)
Line 1: Line 1:
{{stub}}
#redirect [[CHandle]]
 
A common way to address a specific entity is by its entity index ( <code>CBaseEntity::entindex()</code> ). Each time a new entity is instantiated, the engine looks up an unused entity index and assigns it to the new entity. Once the entity object is destroyed, its entity index becomes available again and may be reused for a different entity. Therefore the entity index is not a good way to reference a specific entity over longer times. A better and safer way is to use <code>EHANDLEs</code> (or <code>CBaseHandle</code>) to keep track of entity instances. <code>EHANDLEs</code> encapsulate a 32-bit ID that is unique for an entity instance during the whole game and can be used on both server and client to refer to entity objects (<code>EHANDLEs</code> are a combination of entity index and an increasing serial number). An <code>EHANDLE</code> can be transformed to CBaseEntity and vice versa just by using its overloaded operators. If an <code>EHANDLE</code> resolves to NULL, the entity object is not valid anymore.
 
<pre>
// find a player, if no player is available pPlayer and hPlayer are NULL
EHANDLE hPlayer = gEntList.FindEntityByClassname( NULL, "player" );
CBaseEnity *pPlayer = hPlayer; // convert EHANDLE into entity pointer
m_hPlayer = pPlayer; // convert entity pointer to EHANDLE
</pre>
 
 
==Related content==
[[Networking_Entities#Networking_entities|Networking_Entities]]
 
[[Category:Programming]][[Category:Glossary]]

Latest revision as of 10:09, 9 June 2009

Redirect to: