Every object in TF2 — players, projectiles, pickups, buildings — derives fromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt
Use this file to discover all available pages before exploring further.
CBaseEntity, declared in game/server/baseentity.h. The class implements IServerEntity and drives the networked state, think scheduling, physics collision, and the entity I/O event system that map logic relies on.
Class declaration
DECLARE_SERVERCLASS() / IMPLEMENT_SERVERCLASS_ST() generate the SendTable that the engine uses to delta-compress state to clients. Each subclass that adds network fields pairs these macros with DEFINE_SENDPROP_* entries in its .cpp file.
Networked variables
Networked fields use theCNetworkVar macro family, defined in public/networkvar.h. The underlying CNetworkVarBase<Type, Changer>::Set() calls NetworkStateChanged() whenever the value actually changes, marking the entity dirty for the next network update.
| Macro | Underlying type | Example |
|---|---|---|
CNetworkVar( int, m_iState ) | CNetworkVarBase<int> | Sentry state, teleporter state |
CNetworkVar( float, m_flRechargeTime ) | CNetworkVarBase<float> | Teleporter recharge |
CNetworkVar( bool, m_bDistributed ) | CNetworkVarBase<bool> | Currency pack distributed flag |
CNetworkVarEmbedded( type, name ) | Embedded struct | Aggregate network objects |
Entity I/O
Inputs and outputs connect entities in the map through keyvalue wiring. Theinputdata_t struct carries context for every fired input:
DECLARE_DATADESC() using DEFINE_INPUTFUNC. CBaseObject for example wires:
Think functions
Think callbacks are scheduled per-entity using named think contexts (thinkfunc_t). Each context stores a function pointer, a tick for the next invocation, and the context name string.
SetContextThink( fn, gpGlobals->curtime + delay, "ContextName" ) to schedule a named think, allowing multiple independent think callbacks on a single entity.
Entity handles
EHANDLE (CHandle<CBaseEntity>) is a safe reference type. It validates the serial number on each dereference, returning NULL if the entity has been removed — avoiding dangling pointer crashes common in raw pointer code.