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 class BaseEntityInheritance
Derived
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, 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, string classname)Parameters
system EntitySystem
classname string
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
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
NextThink
Gets the time next runs, in seconds, or -1 when the entity is not thinking.
public float NextThink { get; }Property Value
Origin
Gets or sets the origin. Setting it rebuilds .
public Vector3 Origin { get; set; }Property Value
ParentTransform
Gets the transform of whatever spawned this entity; identity for plain map entities.
public Matrix4x4 ParentTransform { 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.
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)
Puts a node this entity owns into the scene, and takes responsibility for its lifetime and 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)Parameters
node SceneNode
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
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 what the loader draws for an unimplemented classname: 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.
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.
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.
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()
