Class EntityExtensions
- Namespace
- RisingV.Shared.Extensions
- Assembly
- RisingV.Shared.dll
Helper and convenience extensions that operate on Unity DOTS Unity.Entities.Entity values in V Rising server-side code.
The methods fall into three broad groups:
- ECS helpers – raw component/buffer read-write, existence tests, add/remove utilities.
- Gameplay helpers – high-level domain operations such as kill/destroy, team assignment, inventory drops, etc.
- Debug utilities – entity dumps, component stringification, aspect checks.
public static class EntityExtensions
- Inheritance
-
EntityExtensions
- Inherited Members
Methods
Add(Entity, ComponentType)
Adds a component specified by componentType
.
public static void Add(this Entity entity, ComponentType componentType)
Parameters
entity
EntitycomponentType
ComponentType
AddBuffer<T>(Entity)
Adds (or retrieves) a dynamic buffer of type T
.
public static DynamicBuffer<T> AddBuffer<T>(this Entity entity) where T : struct
Parameters
entity
Entity
Returns
- DynamicBuffer<T>
Type Parameters
T
AddWith<T>(Entity, WithRefHandler<T>)
Ensures the entity has component T
(adds if absent)
and routes it through With<T>(Entity, WithRefHandler<T>).
public static void AddWith<T>(this Entity entity, EntityExtensions.WithRefHandler<T> action) where T : struct
Parameters
entity
Entityaction
EntityExtensions.WithRefHandler<T>
Type Parameters
T
Add<T>(Entity)
Adds component T
(zero-initialised).
public static void Add<T>(this Entity entity)
Parameters
entity
Entity
Type Parameters
T
AsPlayerCharacter(Entity)
public static PlayerCharacter? AsPlayerCharacter(this Entity entity)
Parameters
entity
Entity
Returns
- PlayerCharacter?
DebugName(Entity)
public static string DebugName(this Entity entity)
Parameters
entity
Entity
Returns
Destroy(Entity)
Immediately destroys the entity (no checks).
public static void Destroy(this Entity entity)
Parameters
entity
Entity
DestroyWithReason(Entity)
Destroys an entity with proper cleanup and logging.
public static void DestroyWithReason(this Entity entity)
Parameters
entity
EntityThe entity to destroy
Examples
someEntity.DestroyWithReason();
Remarks
This method follows the recommended destruction pattern:
- Disables the entity
- Creates a destroy event for tracking
- Performs the actual entity destruction
DropItemNearby(Entity, PrefabGUID, int)
public static void DropItemNearby(this Entity entity, PrefabGUID itemGuid, int amount)
Parameters
entity
EntityitemGuid
PrefabGUIDamount
int
DropItemNearby(Entity, int, int)
public static void DropItemNearby(this Entity entity, int itemGuidValue, int amount)
Parameters
Dump(Entity, string?, string?, string?)
/// Dumps all component information of an entity to a specified file for debugging purposes.
public static void Dump(this Entity entity, string? prefixDetails = null, string? directoryPath = null, string? fileName = null)
Parameters
entity
EntityThe entity to dump information from
prefixDetails
stringExtra information at the start of the dump
directoryPath
stringThe directory path to write the dump, defaults to
[BepInEx]/plugins/RisingV/DebugDumps
fileName
stringThe file name (with extension) for the dump, defaults to the entity debug name and index
Examples
someEntity.Dump("C:/debug", "entity_dump.txt");
Remarks
The dump includes a list of all components attached to the entity and their detailed information. The output is appended to the specified file with clear section separators.
Exists(Entity)
Checks if the entity exists in the EntityManager.
public static bool Exists(this Entity entity)
Parameters
entity
EntityThe entity to check.
Returns
- bool
True if the entity exists, false otherwise.
GetAimPosition(Entity)
public static float3 GetAimPosition(this Entity entity)
Parameters
entity
Entity
Returns
- float3
GetAndLogPrefabGuid(Entity, string, Logger?)
public static PrefabGUID GetAndLogPrefabGuid(this Entity entity, string logPrefix = "", Logger? logger = null)
Parameters
Returns
- PrefabGUID
GetBuffTarget(Entity)
public static Entity GetBuffTarget(this Entity entity)
Parameters
entity
Entity
Returns
- Entity
GetBufferData(Entity, TypeIndex)
Unsafe pointer to read-only buffer data.
public static void* GetBufferData(this Entity entity, TypeIndex typeIndex)
Parameters
entity
EntitytypeIndex
TypeIndex
Returns
- void*
GetBufferLength(Entity, TypeIndex)
Returns the length of a dynamic buffer without instantiating it.
public static int GetBufferLength(this Entity entity, TypeIndex typeIndex)
Parameters
entity
EntitytypeIndex
TypeIndex
Returns
GetChunk(Entity)
public static TerrainChunk GetChunk(this Entity entity)
Parameters
entity
Entity
Returns
- TerrainChunk
GetChunk(float3)
public static TerrainChunk GetChunk(this float3 pos)
Parameters
pos
float3
Returns
- TerrainChunk
GetComponentData(Entity, TypeIndex)
Unsafe pointer to read-only component data by Unity.Entities.TypeIndex.
public static void* GetComponentData(this Entity entity, TypeIndex typeIndex)
Parameters
entity
EntitytypeIndex
TypeIndex
Returns
- void*
GetEntitiesInArea(Entity, TileType)
Gets entities intersecting the area defined by the entity's ProjectM.TileBounds.
public static NativeArray<Entity> GetEntitiesInArea(this Entity entity, TileType tileType)
Parameters
entity
EntitytileType
TileType
Returns
- NativeArray<Entity>
GetNetworkId(Entity)
public static NetworkId GetNetworkId(this Entity entity)
Parameters
entity
Entity
Returns
- NetworkId
GetPlayerCharacter(Entity)
public static PlayerCharacter? GetPlayerCharacter(this Entity entity)
Parameters
entity
Entity
Returns
- PlayerCharacter?
GetPlayerCharacterEntity(Entity)
public static Entity GetPlayerCharacterEntity(this Entity entity)
Parameters
entity
Entity
Returns
- Entity
GetPosition(Entity)
public static float3 GetPosition(this Entity entity)
Parameters
entity
Entity
Returns
- float3
GetPrefabGuid(Entity)
public static PrefabGUID GetPrefabGuid(this Entity entity)
Parameters
entity
Entity
Returns
- PrefabGUID
GetSpawnPosition(Entity)
public static float3 GetSpawnPosition(this Entity entity)
Parameters
entity
Entity
Returns
- float3
GetSpellTarget(Entity)
public static Entity GetSpellTarget(this Entity entity)
Parameters
entity
Entity
Returns
- Entity
GetSteamId(Entity)
public static ulong GetSteamId(this Entity entity)
Parameters
entity
Entity
Returns
GetUser(Entity)
public static User GetUser(this Entity entity)
Parameters
entity
Entity
Returns
- User
GetUserEntity(Entity)
public static Entity GetUserEntity(this Entity entity)
Parameters
entity
Entity
Returns
- Entity
Has(Entity, ComponentType)
Component existence check taking an explicit Unity.Entities.ComponentType.
public static bool Has(this Entity entity, ComponentType componentType)
Parameters
entity
EntitycomponentType
ComponentType
Returns
HasBuff(Entity, PrefabGUID)
public static bool HasBuff(this Entity entity, PrefabGUID buffPrefabGuid)
Parameters
entity
EntitybuffPrefabGuid
PrefabGUID
Returns
HasConnectedCoffin(Entity)
public static bool HasConnectedCoffin(this Entity entity)
Parameters
entity
Entity
Returns
HasRaw<T>(Entity)
Checks for component presence using the raw API (slightly faster than the managed overload).
public static bool HasRaw<T>(this Entity entity) where T : struct
Parameters
entity
Entity
Returns
Type Parameters
T
Has<T>(Entity)
Generic component existence check.
public static bool Has<T>(this Entity entity)
Parameters
entity
Entity
Returns
Type Parameters
T
IsAspect<TAspect>(object)
public static bool IsAspect<TAspect>(this object entity) where TAspect : IAspect
Parameters
entity
object
Returns
Type Parameters
TAspect
IsCustomSpawned(Entity)
public static bool IsCustomSpawned(this Entity entity)
Parameters
entity
Entity
Returns
IsDead(Entity)
public static bool IsDead(this Entity entity)
Parameters
entity
Entity
Returns
IsDisabled(Entity)
Checks if the entity is disabled.
public static bool IsDisabled(this Entity entity)
Parameters
entity
EntityThe entity to check.
Returns
- bool
True if the entity is disabled, false otherwise.
IsNull(Entity)
public static bool IsNull(this Entity entity)
Parameters
entity
Entity
Returns
KillOrDestroy(Entity)
Kills or destroys an entity based on game rules and conditions.
public static void KillOrDestroy(this Entity entity)
Parameters
entity
EntityThe entity to kill or destroy
Examples
someEntity.KillOrDestroy();
Remarks
This method uses the StatChangeUtility to process the entity's death or destruction. The same entity is used for source, target, and instigator parameters.
PrintComponentTypes(Entity, bool, string)
public static void PrintComponentTypes(this Entity entity, bool printError = true, string separator = "\n")
Parameters
ReadBuffer<T>(Entity)
Returns a dynamic buffer of type T
.
Throws if the buffer is missing.
public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
Parameters
entity
Entity
Returns
- DynamicBuffer<T>
Type Parameters
T
ReadTry<T>(Entity)
Safe wrapper around Read<T>(Entity) that returns null instead of throwing when the component is missing.
public static T? ReadTry<T>(this Entity entity) where T : struct
Parameters
entity
Entity
Returns
- T?
Type Parameters
T
Read<T>(Entity)
Raw read-only access to component T
.
public static T Read<T>(this Entity entity) where T : struct
Parameters
entity
Entity
Returns
- T
Type Parameters
T
Remove<T>(Entity)
Removes component T
from the entity.
public static void Remove<T>(this Entity entity)
Parameters
entity
Entity
Type Parameters
T
SetBufferData<T>(Entity, T[])
Clears (or creates) a dynamic buffer and fills it with
bufferArray
.
public static void SetBufferData<T>(this Entity prefabSource, T[] bufferArray) where T : struct
Parameters
prefabSource
EntitybufferArray
T[]
Type Parameters
T
SetComponentData(Entity, TypeIndex, void*, int)
Unsafe raw setter for component data.
public static void SetComponentData(this Entity entity, TypeIndex typeIndex, void* byteData, int size)
Parameters
SetFaction(Entity, PrefabGUID)
public static void SetFaction(this Entity entity, PrefabGUID factionPrefabGuid)
Parameters
entity
EntityfactionPrefabGuid
PrefabGUID
SetTeam(Entity, Entity)
public static void SetTeam(this Entity entity, Entity teamSource)
Parameters
entity
EntityteamSource
Entity
SortByDistance(NativeArray<Entity>, float3)
Sorts an array of entities by their distance from a given position.
public static NativeArray<Entity> SortByDistance(this NativeArray<Entity> entities, float3 position)
Parameters
entities
NativeArray<Entity>The array of entities to sort
position
float3The reference position to measure distances from
Returns
- NativeArray<Entity>
The sorted array of entities
StructureToByteArray<T>(T)
Marshals a blittable struct into a byte array.
Primarily used by Write<T>(Entity, T).
public static byte[] StructureToByteArray<T>(T structure) where T : struct
Parameters
structure
T
Returns
- byte[]
Type Parameters
T
ToComponentString(Entity, string)
public static string ToComponentString(this Entity entity, string separator = "\n - ")
Parameters
entity
Entityseparator
string
Returns
TryGetBuff(Entity, PrefabGUID, out Entity)
public static bool TryGetBuff(this Entity entity, PrefabGUID buffPrefabGuid, out Entity buffEntity)
Parameters
entity
EntitybuffPrefabGuid
PrefabGUIDbuffEntity
Entity
Returns
TryGetBuffer<T>(Entity, out DynamicBuffer<T>)
Attempts to get a dynamic buffer without throwing.
public static bool TryGetBuffer<T>(this Entity entity, out DynamicBuffer<T> dynamicBuffer) where T : struct
Parameters
entity
EntitydynamicBuffer
DynamicBuffer<T>
Returns
Type Parameters
T
TryGetComponentObject<T>(Entity, EntityManager, out T?)
Attempts to obtain a managed component object.
public static bool TryGetComponentObject<T>(this Entity entity, EntityManager entityManager, out T? componentObject) where T : class
Parameters
entity
EntityentityManager
EntityManagercomponentObject
T
Returns
Type Parameters
T
TryGetComponent<T>(Entity, out T)
Attempts to read component T
without throwing.
public static bool TryGetComponent<T>(this Entity entity, out T componentData) where T : struct
Parameters
entity
EntitycomponentData
T
Returns
Type Parameters
T
TryGetFollower(Entity, out Entity)
public static bool TryGetFollower(this Entity source, out Entity result)
Parameters
source
Entityresult
Entity
Returns
TryGetMatch(HashSet<(ulong, ulong)>, ulong, out (ulong, ulong))
public static bool TryGetMatch(this HashSet<(ulong, ulong)> hashSet, ulong value, out (ulong, ulong) matchingPair)
Parameters
Returns
TryGetPosition(Entity, out float3)
public static bool TryGetPosition(this Entity entity, out float3 position)
Parameters
entity
Entityposition
float3
Returns
TryGetTeamEntity(Entity, out Entity)
public static bool TryGetTeamEntity(this Entity entity, out Entity teamEntity)
Parameters
entity
EntityteamEntity
Entity
Returns
TryRemoveComponent<T>(Entity)
Removes component T
if present and returns
true
on success.
public static bool TryRemoveComponent<T>(this Entity entity) where T : struct
Parameters
entity
Entity
Returns
Type Parameters
T
With<T>(Entity, WithRefHandler<T>)
Reads component T
, executes action
,
then writes the component back to the entity.
public static void With<T>(this Entity entity, EntityExtensions.WithRefHandler<T> action) where T : struct
Parameters
entity
EntityTarget entity.
action
EntityExtensions.WithRefHandler<T>Mutation delegate.
Type Parameters
T
Component type.
Write<T>(Entity, T)
Writes unmanaged component data using the raw pointer API for maximum performance (no boxing or GC allocations).
public static void Write<T>(this Entity entity, T componentData) where T : struct
Parameters
entity
EntitycomponentData
T
Type Parameters
T