Difference between revisions of "Activate()"

From Valve Developer Community
Jump to: navigation, search
(Fixed some misinformation)
m (Took out too much)
Line 9: Line 9:
 
{{tip|<code>Activate()</code> is not related to entity [[input]]s or [[flag]]s of the same name. It is ''always'' called.}}
 
{{tip|<code>Activate()</code> is not related to entity [[input]]s or [[flag]]s of the same name. It is ''always'' called.}}
  
{{note|If an entity is spawned via game code (ex:<code>CreateEntityByName()</code>) then <code>Activate()</code>  is ''not'' called so be sure to call <code>Activate()</code> from the spawning code.  Also note that <code>Activate()</code>  is not called for client-side entities.<br>.}}
+
{{note|If an entity is spawned from the console (ex:<code>ent_create</code>) or via game code (ex:<code>CreateEntityByName()</code>) then <code>Activate()</code>  is ''not'' called so be sure to call <code>Activate()</code> from the spawning code.  Also note that <code>Activate()</code>  is not called for client-side entities.<br>.}}
  
 
== Example ==
 
== Example ==

Revision as of 04:05, 30 December 2009

The Source engine entity initialisation process.

Activate() is a void member function of CBaseEntity that is available through inheritance to every entity in a Source game. It is called by the engine after Spawn() and, if Spawn() occurred during a map's initial load, after all other entities have been spawned too.

Activate() is used to perform spawning tasks that require interaction with other entities. Such tasks should never be performed in Spawn() itself, as it may be called before any other entities become available.

Warning: CBaseEntity executes code in this function, so always call BaseClass::Activate() from your version.

Tip:Activate() is not related to entity inputs or flags of the same name. It is always called.
Note:If an entity is spawned from the console (ex:ent_create) or via game code (ex:CreateEntityByName()) then Activate() is not called so be sure to call Activate() from the spawning code. Also note that Activate() is not called for client-side entities.
.

Example

void CAlyxEmpEffect::Activate()
{
	// Start out with a target entity
	SetTargetEntity( STRING(m_strTargetName) );
	
	BaseClass::Activate();
}

See also