Generalities On Entities
- 1 Introduction
- 2 Naming conventions
- 3 Base classes
- 4 Think functions
- 5 Macros
This article is mainly about entities in the Source engine and will try to explain everything about entities.
Every object, even the world, is an entity in the Source engine. All entities are derived from CBaseEntity.
Within the Source SDK, server classes begin with a capital C (
C), while client classes begin with a capital C followed by an underscore (
C_) - this helps differentiate between the two code bases.
Server: CMyEntity Client: C_MyEntity
The style of naming convention followed through the SDK code base is known as Hungarian notation. Beginners are recommended to maintain the same style as used throughout the code base to save confusion.
Every entity is based on
CBaseEntity, however there are many derived classes. The following is a list of the more common derived classes.
Every entity that has a model uses CBaseAnimating. Classes derived from CBaseAnimating can set a model and animate.
AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
Triggers are brush based entities that are generally placed during the map creation process.
This entity is the player itself. Every player-entity in the game is CBasePlayer or is derived from this entity.
This entity regulates the rules of the current game. It's mainly the gameplay.
Every NPC & player are derived from this class.
- Main article: Think()
Think functions are a group of functions comprising the main way to have an entity act without input. An entity's Think() is run once after it spawns, and can be told when to call itself again using SetNextThink(). Using SetThink() can change between several Think() functions, and GetLastThink() returns the time of the last think function. See Think() for detailed description.
Badly set up macros will give error messages, crash the game and cause erratic behavior. The following is a list of the more common macro definitions and some of the issues that surround them.
This is one of the main macros. An entity cannot be created without this macro being used to define the entity's classname (as returned from
GetClassname() on the server). However, on the client, an entity will not return its classname unless there is a matching data description (
This is used to tell the engine that it needs to precache the entity when it loads. This is provided with the name of the entity (the same name as passed to LINK_ENTITY_TO_CLASS() ).
This should be placed in the public section of an entity's Class definition. This provides access to the BaseClass Macro.
The Data Description macros provide for a number of different features;
- Specifying Think and Touch functions
- Providing Inputs and Outputs for mappers
- Providing external variable inputs (such as setting a model or the health of an item)
Further information is available on the Data Descriptions page.
See the Networking section for more information on networking entities, as that is outside the scope of this article.