Class BaseEntity
Namespace: ValveResourceFormat.Renderer.Entities
Assembly: Renderer.dll
The base of the simulated entity hierarchy, Source's CBaseEntity. It carries the origin and angles, ticks inside , and owns the scene nodes that draw it.
public abstract class BaseEntityInheritance
Derived
AmbientGeneric, BaseModelEntity, CS2Projectile, EnvCubemapFog, EnvExplosion, EnvGradientFog, EnvLightingVolume, EnvSky, EnvSoundscape, EnvTonemapController, FilterActivatorModel, GenericEntity, InfoMapParameters, InfoParticleSystem, InfoVisibilityBox, InfoWorldLayer, LightEntity, LogicAuto, LogicCase, LogicRelay, LogicTimer, MathCounter, PathParticleRopeEntity, PlayerEntity, PointCamera, PointSoundEvent, SpawnPoint, WorldEntity
Remarks
Entities move on the fixed tick rather than the render frame, so think intervals and ramps match the engine at any framerate. An entity is not a scene node; it owns one, , and places it each frame. That node defaults to the editor box, and a class with real geometry replaces it.
Constructors
BaseEntity(EntitySystem, EntitySpawnInfo)
Initializes the entity from its keyvalues, reading the properties every entity has.
protected BaseEntity(EntitySystem system, EntitySpawnInfo spawnInfo)Parameters
system EntitySystem
spawnInfo EntitySpawnInfo
BaseEntity(EntitySystem, Scene, string)
Initializes an entity created at runtime rather than loaded from a map, so it has no keyvalues to read and starts at the world origin.
protected BaseEntity(EntitySystem system, Scene scene, string classname)Parameters
system EntitySystem
The entity world it lives in.
scene Scene
The scene its nodes render into.
classname string
The classname it reports.
Properties
Angles
Gets or sets the orientation as a QAngle (pitch, yaw, roll) in degrees. Setting it rebuilds .
public Vector3 Angles { get; set; }Property Value
AngularVelocity
Gets or sets the angular velocity as a QAngle in degrees per second, turning the entity about its own axes. Source's SetLocalAngularVelocity.
public Vector3 AngularVelocity { get; set; }Property Value
Classname
Gets the entity's classname.
public string Classname { get; }Property Value
Collider
Gets the entity's collision shape, or null when it has none. Built by
from the model's physics, and moved with the entity every tick.public EntityCollider? Collider { get; protected set; }Property Value
Data
Gets the entity's keyvalues as authored in the map, or null for an entity created at runtime rather than loaded from one. Use from a class that only ever comes from a map.
public EntityLump.Entity? Data { get; }Property Value
EntityScale
Gets the authored scales, which movement never changes.
public Vector3 EntityScale { get; }Property Value
EntitySystem
Gets the world this entity lives in.
public EntitySystem EntitySystem { get; }Property Value
IsCollidable
Gets whether the entity currently takes part in collision traces.
public bool IsCollidable { get; }Property Value
IsDrawn
Gets or sets whether the entity's geometry is drawn, Source's EF_NODRAW. Every node it owns follows, through , so toggling costs nothing.
public bool IsDrawn { get; set; }Property Value
IsPusher
Gets whether this entity shoves the player out of its way as it moves, Source's MOVETYPE_PUSH. Doors, buttons and rotating brushes opt in.
protected virtual bool IsPusher { get; }Property Value
IsRemoved
Gets whether this entity has been removed from the world and is awaiting cleanup.
public bool IsRemoved { get; }Property Value
IsSolid
Gets or sets whether the entity collides with the player. Setting it to false leaves the shape built but takes the entity out of traces, which is what Source's SOLID_NONE amounts to here.
public bool IsSolid { get; set; }Property Value
IsTrigger
Gets or sets whether the entity is a trigger volume: something passes through it and it reports the touch, rather than blocking. Source's FSOLID_TRIGGER.
public bool IsTrigger { get; set; }Property Value
KeyValues
Gets the map keyvalues this entity was authored with. Throws for an entity created at runtime, which has none; read instead in a class that can be either.
protected EntityLump.Entity KeyValues { get; }Property Value
LayerName
Gets the visibility layer this entity's nodes belong to.
public string? LayerName { get; }Property Value
ModelName
Gets the model the map authored. Source's m_ModelName. Reading the keyvalue is generic; an entity that has something to draw applies it by deriving from .
public string? ModelName { get; protected set; }Property Value
MoveDoneTime
Gets the time next runs, in seconds, or -1 when no move is scheduled. Source's m_flMoveDoneTime, how pushing entities step their movement state machines.
public float MoveDoneTime { get; }Property Value
MoveParent
Gets the entity this one moves with, the map's parentname - the move parent, which is a different link than . A door's handle rides its door through this.
public BaseEntity? MoveParent { get; }Property Value
NextThink
Gets the time next runs, in seconds, or -1 when the entity is not thinking.
public float NextThink { get; }Property Value
ObjectCaps
Gets what this entity can do, which is how the player's use trace decides whether it is worth pressing. Source's ObjectCaps.
public virtual EntityCapability ObjectCaps { get; }Property Value
Origin
Gets or sets the origin. Setting it rebuilds .
public Vector3 Origin { get; set; }Property Value
Owner
Gets or sets the owning entity, Source's m_hOwnerEntity. Null only on the root .
public BaseEntity? Owner { get; set; }Property Value
ParentTransform
Gets the transform of whatever spawned this entity; identity for plain map entities.
public Matrix4x4 ParentTransform { get; }Property Value
PusherForcesThrough
Gets whether a blocked push crushes on rather than holding, the forceclosed behaviour.
protected virtual bool PusherForcesThrough { get; }Property Value
RigidTransform
Gets where the entity is in the world at its current tick, without its : the placement of anything the scale must not stretch, such as collision or a baked volume.
public Matrix4x4 RigidTransform { get; }Property Value
RootNode
Gets the node this entity is drawn as, from . The entity positions it; anything hanging off it follows by the scene graph's own rules.
public SceneNode? RootNode { get; }Property Value
Scene
Gets the scene this entity's nodes live in: the map's, or the 3D skybox's for one spawned there.
public Scene Scene { get; }Property Value
SpawnFlags
Gets the entity's spawnflags.
public uint SpawnFlags { get; }Property Value
TargetName
Gets the entity's targetname, the name entity I/O addresses it by.
public string? TargetName { get; }Property Value
TouchingEntities
Gets the entities currently inside this one's volume.
public IReadOnlyCollection<BaseEntity> TouchingEntities { get; }Property Value
IReadOnlyCollection<BaseEntity>
Transform
Gets the world transform the entity is drawn at, interpolated between ticks.
public Matrix4x4 Transform { get; }Property Value
Velocity
Gets or sets the linear velocity in units per second.
public Vector3 Velocity { get; set; }Property Value
Methods
AcceptInput(string, EntityInputData)
Handles an entity I/O input fired at this entity, by running the handler this entity's class declared for it with . Override only to intercept inputs that cannot be a fixed method, and call the base to fall back to the table.
public virtual bool AcceptInput(string inputName, EntityInputData data)Parameters
inputName string
data EntityInputData
Returns
true when the input was handled.
AcceptsTouchFrom(BaseEntity)
Whether this entity is interested in being touched by other. A refusal keeps the touch link from opening at all, which is where a trigger's filters belong.
protected virtual bool AcceptsTouchFrom(BaseEntity other)Parameters
other BaseEntity
Returns
Activate()
Called once every entity in the map has spawned, for anything that needs to resolve other entities by name. Source's Activate.
public virtual void Activate()AddNode(SceneNode, bool)
Puts a node this entity owns into the scene, and takes responsibility for its lifetime, whether it is drawn, and by default its placement. is the one the entity is drawn as; a model entity also owns the collision hulls its model was compiled with.
protected void AddNode(SceneNode node, bool followsEntity = true)Parameters
node SceneNode
The node to own.
followsEntity bool
Whether the entity places the node at itself. Pass false for a node placed some other way, such as an effect whose control point 0 belongs to another entity.
AngleMod(float)
Wraps an angle into [0, 360), the way the engine's anglemod does, quantization included, so comparisons against a stored angle behave the same here as they do in Source.
public static float AngleMod(float degrees)Parameters
degrees float
Returns
CreateEditorNode(ObjectTypeFlags)
Builds the node the editor draws this entity as: the icon its Hammer class names, or a box in its colour. null for an entity created at runtime, which has no Hammer class.
protected SceneNode? CreateEditorNode(ObjectTypeFlags flags = ObjectTypeFlags.None)Parameters
flags ObjectTypeFlags
Flags for the node.
Returns
The node, or null.
CreateEffect(string?, ParticleSnapshot?, bool)
Loads an effect for the entity to play, at the entity and on the particles layer. The caller decides whether the entity owns and places it, through .
protected ParticleSceneNode? CreateEffect(string? effectName, ParticleSnapshot? snapshot = null, bool playedByEntity = true)Parameters
effectName string?
The effect, or null or empty for none.
snapshot ParticleSnapshot?
A snapshot the effect starts from, such as a rope's points.
playedByEntity bool
Whether the entity sets the control points, rather than the effect's own configuration.
Returns
The effect, or null when there is none or it failed to load.
CreateRootNode()
Builds the node this entity is drawn as, or returns null for one that draws nothing.
protected virtual SceneNode? CreateRootNode()Returns
The node, or null to own none.
Remarks
The default is the editor marker, : the icon the entity's Hammer class names, or a box in its colour. A class with real geometry overrides this, so the icon is never built for one that has geometry.
GetSurfaceVelocity(Vector3)
The velocity of this entity's surface at a world position: linear plus the angular sweep.
public Vector3 GetSurfaceVelocity(Vector3 at)Parameters
at Vector3
Returns
HasSpawnFlags<TSpawnFlags>(TSpawnFlags)
Tests whether any of the given spawnflags bits are set, as Source's HasSpawnFlags does. Each entity class declares what its flags mean as a enum backed by
public bool HasSpawnFlags<TSpawnFlags>(TSpawnFlags flags) where TSpawnFlags : struct, EnumParameters
flags TSpawnFlags
Returns
Type Parameters
TSpawnFlags
The entity class's spawnflags enum.
InputFireUser1(EntityInputData)
Fires the OnUser1 output; every entity answers FireUser1.
[EntityInput("FireUser1")]
protected void InputFireUser1(EntityInputData data)Parameters
data EntityInputData
InputFireUser2(EntityInputData)
Fires the OnUser2 output.
[EntityInput("FireUser2")]
protected void InputFireUser2(EntityInputData data)Parameters
data EntityInputData
InputFireUser3(EntityInputData)
Fires the OnUser3 output.
[EntityInput("FireUser3")]
protected void InputFireUser3(EntityInputData data)Parameters
data EntityInputData
InputFireUser4(EntityInputData)
Fires the OnUser4 output.
[EntityInput("FireUser4")]
protected void InputFireUser4(EntityInputData data)Parameters
data EntityInputData
InputKill(EntityInputData)
Removes the entity from the world.
[EntityInput("Kill")]
protected void InputKill(EntityInputData data)Parameters
data EntityInputData
MoveDone()
Runs when comes due, after the tick's movement was applied.
public virtual void MoveDone()OnEndTouch(BaseEntity)
Runs on the tick other leaves this entity's volume. Source's EndTouch.
protected virtual void OnEndTouch(BaseEntity other)Parameters
other BaseEntity
OnRemove()
Called as the entity leaves the world, before its nodes are taken out of the scene. Source's UpdateOnRemove: the place to let go of anything the entity started, such as a playing sound.
protected virtual void OnRemove()OnStartTouch(BaseEntity)
Runs on the tick other enters this entity's volume. Source's StartTouch.
protected virtual void OnStartTouch(BaseEntity other)Parameters
other BaseEntity
OnTouch(BaseEntity)
Runs every tick other stays inside this entity's volume. Source's Touch.
protected virtual void OnTouch(BaseEntity other)Parameters
other BaseEntity
PhysicsSimulate(float)
Integrates this tick's movement, advancing by and turning by .
protected virtual void PhysicsSimulate(float tickInterval)Parameters
tickInterval float
Remarks
The turn goes about the entity's own axes, not onto the QAngle components. Source 1 adds the components (physics_main.cpp: angles += GetLocalAngularVelocity() * movetime), Source 2 turns the body, and these are Source 2 maps. The two only differ for an entity the map already rotated, such as a brush authored on its side, which would otherwise yaw about the world's up axis.
RoundStart()
Runs when the host declares a round started, via . What the engine's game rules announce to entities on round restart.
public virtual void RoundStart()SetMoveDoneTime(float)
Schedules to run after a delay in seconds, matching Source's SetMoveDoneTime. A negative delay cancels the scheduled move.
public void SetMoveDoneTime(float delay)Parameters
delay float
SetNextThink(float)
Schedules to run at an absolute in seconds; -1 stops thinking.
public void SetNextThink(float time)Parameters
time float
SetOriginAndAngles(Vector3, Vector3)
Moves and turns in one go, so a tick's movement rebuilds the transform once rather than once per property, and an unchanged write costs nothing.
protected void SetOriginAndAngles(Vector3 newOrigin, Vector3 newAngles)Parameters
newOrigin Vector3
newAngles Vector3
SnapInterpolation()
Drops the interpolation history, so the entity is drawn at its current state instead of sliding there from where it was. Source's Interp_Reset; call it after a teleport or any other jump that is not movement.
protected void SnapInterpolation()Spawn()
Sets up the entity: loads its model, reads class-specific keyvalues, and schedules its first think. Called by right after construction, before the entity enters the world.
public virtual void Spawn()Teleport(Vector3, Vector3?)
Moves the entity somewhere else outright, rather than by travelling there. Source's CBaseEntity::Teleport. Null angles keep the current ones.
public virtual void Teleport(Vector3 origin, Vector3? angles)Parameters
origin Vector3
angles Vector3?
Think()
Runs when comes due.
public virtual void Think()TryGetTouchBounds(out Vector3, out Vector3)
Reports the box this entity occupies for touch tests, which by default is the world-space bounds of its collision shape. An entity with no shape has no volume and cannot be touched, so it says so.
public virtual bool TryGetTouchBounds(out Vector3 center, out Vector3 halfExtents)Parameters
center Vector3
halfExtents Vector3
Returns
true when this entity occupies space.
Remarks
A box rather than the real shape, because that is what trigger volumes test against, here and in the engine.
TurnBody(Vector3, Vector3)
Turns a QAngle by a delta given in the body's own frame, and reports where that lands as a QAngle.
protected static Vector3 TurnBody(Vector3 from, Vector3 bodyDelta)Parameters
from Vector3
bodyDelta Vector3
Returns
UpdateColliderTransform()
Moves the collision shape onto the entity's current tick state.
protected void UpdateColliderTransform()Remarks
Uses the tick state, not the interpolated one drawn this frame, because collision answers where the entity is - the same split the engine has between the server tracing and the client drawing. The transform stays rigid, leaving out, because the shape's sweeps assume distances do not change in its local space.
UpdateRenderTransform(float)
Rebuilds for drawing, somewhere between the last two ticks.
protected virtual void UpdateRenderTransform(float fraction)Parameters
fraction float
Remarks
The engine's client-side interpolation: draw between the two most recent tick states instead of the newest one, which renders slightly in the past but stays smooth at any framerate. Angles slerp, like mathlib's Lerp<QAngle>, taking the shortest arc. Only what is drawn changes; the tick state stays authoritative.
UpdateTransform()
Rebuilds from the current scale, angles, and origin.
protected void UpdateTransform()Use(BaseEntity?)
Runs when something presses this entity. Source's CBaseEntity::Use, minus the use type and value, which nothing here distinguishes.
public virtual void Use(BaseEntity? activator)Parameters
activator BaseEntity?

