Entities
Entities are objects that can be placed within the game world, such as props, players, spawnpoints. They can be created and spawned with the C# API, or automatically as part of a level.
Entity is the base class for all entities.
RenderEntity extends Entity and can be used for custom rendering.
ModelEntity extends Entity and adds support for non-animated models.
- AnimatedEntity extends ModelEntity and adds support for animated models.
Spawning Entities
Creating a new instance of an Entity class automatically spawns the entity into the world.
Spawning an Entity calls the virtual method Entity.Spawn() and if replicated on the client Entity.ClientSpawn().
Spawn
method on an entity will be called before its constructor is finished. Related issue: #2282Creating with the TypeLibrary
You can also create an instance of an entity by using the TypeLibrary
if you have registered the entity by using the [Library]
decorator.
Events / Overrides
When entities are created and destroyed they are automatically registered to recieve events from the Event System.
In addition to the event system, entities have plenty of virtual methods you can override, you can use intellisense to find all of them.
Networking / Replication
Entities are replicated from the server to clients based on what Entity.Transmit is set to. By default entites are only transmitted to clients that can see them.
When an entity is replicated any properties marked as a Networked Type are replicated to the entity on the client too.
Components
Entities can have entity components, these are replicated on clients automatically.
Hammer and other tools
Entities can be linked to tools such as Hammer. More information about the process can be found on this page
Deleting Entities
Entities are not garbage collected like a normal C# class as they belong to the world. Entities can be explicitly deleted by calling Entity.Delete(), these entities are then invalid and should not be used anymore.
Any reference to a deleted Entity will return false on Entity.IsValid(), you should use this instead of a null check on entities.