Skip to content

Class Group ​

Namespace: KenseiECS

Owning group: keeps the dense arrays of its pools aligned so that every entity holding all owned components sits at the same dense index in each pool, packed at the front. Iteration then reads the component arrays directly — no sparse lookups, one bounds check per span.

A pool can be owned by one group only. Entities gain and lose membership as components are added and removed; the group is always exact.

Usage:

csharp
var group = world.Group<Position, Velocity>();
var pos = group.Data1;
var vel = group.Data2;
for (int i = 0; i < pos.Length; i++) {
    pos[i].X += vel[i].X;
}

Iterate in reverse when destroying entities or removing owned components inside the loop: the last member is swapped into the freed slot.

csharp
public abstract class Group

Inheritance ​

object ← Group

Derived ​

Group<T1, T2>, Group<T1, T2, T3, T4>, Group<T1, T2, T3>

Inherited Members ​

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

Properties ​

Count ​

Number of entities holding every owned component.

csharp
public int Count { get; }

Property Value ​

int

Entities ​

Entity indices of the members, aligned with the data spans.

csharp
public ReadOnlySpan<int> Entities { get; }

Property Value ​

ReadOnlySpan<int>

PoolCount ​

Number of owned component pools.

csharp
public int PoolCount { get; }

Property Value ​

int

Methods ​

GetPool(int) ​

Owned pool at index, in type-argument order.

csharp
public ComponentPoolBase GetPool(int index)

Parameters ​

index int

Pool index, from 0 to PoolCount - 1.

Returns ​

ComponentPoolBase

The owned component pool.