Activate(): Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(noted Activate() is not called for client entities spawned after map load)
Line 8: Line 8:


{{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|When an entity is spawned form the console (ex:<code>CreateEntityByName()</code>) <code>Activate()</code> is ''not'' called.  For server-side entities <code>Activate()</code> can be called directly.  The best known work around for client-side entities is to use a think function instead.}}


== Example ==
== Example ==

Revision as of 22:40, 28 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.pngWarning:CBaseEntity executes code in this function, so always call BaseClass::Activate() from your version.
Tip.pngTip:Activate() is not related to entity inputs or flags of the same name. It is always called.
Note.pngNote:When an entity is spawned form the console (ex:CreateEntityByName()) Activate() is not called. For server-side entities Activate() can be called directly. The best known work around for client-side entities is to use a think function instead.

Example

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

See also