Skip to content

Struct Entity ​

Namespace: KenseiECS

Lightweight entity identifier (8 bytes). Contains slot index and generation as separate ints. Generation is used to detect stale references: when a slot is reused, generation increments, making all old Entity values with the previous generation invalid.

csharp
public readonly struct Entity : IEquatable<Entity>

Implements ​

IEquatable<Entity>

Inherited Members ​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Fields ​

Generation ​

Slot generation — increments each time a slot is reused.

csharp
public readonly int Generation

Field Value ​

int

Index ​

Slot index in World entity arrays.

csharp
public readonly int Index

Field Value ​

int

Null ​

Invalid entity — default(Entity) = (0, 0), never matches a real entity (generations start at 1).

csharp
public static readonly Entity Null

Field Value ​

Entity

Methods ​

Equals(Entity) ​

True when both index and generation match.

csharp
public bool Equals(Entity other)

Parameters ​

other Entity

Returns ​

bool

Equals(object) ​

True when obj is an Entity with the same index and generation.

csharp
public override bool Equals(object obj)

Parameters ​

obj object

Returns ​

bool

GetHashCode() ​

Hash combining index and generation.

csharp
public override int GetHashCode()

Returns ​

int

ToString() ​

Formats as index and generation, e.g. E(5v2).

csharp
public override string ToString()

Returns ​

string

Operators ​

operator ==(Entity, Entity) ​

True when both index and generation match.

csharp
public static bool operator ==(Entity a, Entity b)

Parameters ​

a Entity

b Entity

Returns ​

bool

operator !=(Entity, Entity) ​

True when index or generation differ.

csharp
public static bool operator !=(Entity a, Entity b)

Parameters ​

a Entity

b Entity

Returns ​

bool