Struct EntityRef
Zero-copy entity accessor. A ref struct (~96 bytes) that copies the EntityRecord from the per-archetype LinearHash and provides typed component access via cached Location ChunkIds.
public ref struct EntityRef
- Inherited Members
Remarks
Created by Open(EntityId) or OpenMut(EntityId). Must not outlive the creating accessor.
Read/Write operations delegate to the EntityAccessor for chunk accessor management.
Properties
ArchetypeId
The archetype ID of this entity.
public ushort ArchetypeId { get; }
Property Value
ComponentCount
Number of component slots declared by this entity's archetype. Slots are addressable [0, ComponentCount).
public int ComponentCount { get; }
Property Value
Id
The entity's unique identifier.
public EntityId Id { get; }
Property Value
IsValid
True if this EntityRef refers to a valid entity.
public bool IsValid { get; }
Property Value
IsWritable
True if this EntityRef allows writes.
public bool IsWritable { get; }
Property Value
Methods
Disable<T>(Comp<T>)
Disable a component by handle. Stages the change for commit.
public void Disable<T>(Comp<T> comp) where T : unmanaged
Parameters
compComp<T>
Type Parameters
T
Enable<T>(Comp<T>)
Enable a component by handle. Stages the change for commit.
public void Enable<T>(Comp<T> comp) where T : unmanaged
Parameters
compComp<T>
Type Parameters
T
GetComponentName(int)
The registered name of the component at slot — matches ComponentTable.Definition.Name (the join key for the schema layout).
Pairs with ReadRaw(int) for runtime, non-generic component decode.
public string GetComponentName(int slot)
Parameters
slotint
Returns
IsEnabled(byte)
Check if a component at the given slot is enabled.
public bool IsEnabled(byte slotIndex)
Parameters
slotIndexbyte
Returns
IsEnabled<T>(Comp<T>)
Check if a component is enabled by handle.
public bool IsEnabled<T>(Comp<T> comp) where T : unmanaged
Parameters
compComp<T>
Returns
Type Parameters
T
ReadRaw(int)
Read the raw storage bytes of the component at slot — the non-generic counterpart to Read<T>() for tooling that decodes
components by field layout at runtime (e.g. the Workbench Data Browser). The returned span points directly into mapped page / cluster memory (zero-copy)
and is valid only while this EntityRef is alive. Its length is the component's storage size; field values are decoded by the caller using
the component's field offsets. MVCC-correct: Versioned slots resolve to the content visible at the owning transaction's snapshot. Works regardless of the
component's enabled state — query IsEnabled(byte) separately to render disabled components.
Prefer the typed Read<T>() / TryRead<T>(out T) whenever the component type is known at compile time — they return a typed (zero-copy) ref with no manual offset decoding. Reach for ReadRaw(int) only when the component type is not available statically.
public ReadOnlySpan<byte> ReadRaw(int slot)
Parameters
slotint
Returns
Read<T>()
Read a component by type. Resolves slot via archetype metadata.
public ref readonly T Read<T>() where T : unmanaged
Returns
- T
Type Parameters
T
Read<T>(Comp<T>)
Read a component by handle. Zero-copy — returns a ref into the chunk page (or cluster slot).
public ref readonly T Read<T>(Comp<T> comp) where T : unmanaged
Parameters
compComp<T>
Returns
- T
Type Parameters
T
TryRead<T>(out T)
Attempt to read a component by type. Returns false if the archetype doesn't declare the component or it's disabled.
Returns a copy (not ref) since out parameters can't be ref readonly.
For zero-copy, use if (entity.IsEnabled(comp)) { ref readonly var v = ref entity.Read(comp); }.
public bool TryRead<T>(out T value) where T : unmanaged
Parameters
valueT
Returns
Type Parameters
T
Write<T>()
Write a component by type. Resolves slot via archetype metadata. For Versioned: copy-on-write (allocates new chunk, preserves old for concurrent readers). For SingleVersion with indexes: shadows old field values on first write per tick for deferred index maintenance.
public ref T Write<T>() where T : unmanaged
Returns
- T
Type Parameters
T
Write<T>(Comp<T>)
Write a component by handle. Returns a mutable ref into the chunk page (or cluster slot). For Versioned: copy-on-write (allocates new chunk, preserves old for concurrent readers). For SingleVersion with indexes: shadows old field values on first write per tick for deferred index maintenance.
public ref T Write<T>(Comp<T> comp) where T : unmanaged
Parameters
compComp<T>
Returns
- T
Type Parameters
T