EasyEcs
API reference

DynamicBuffer<T>

A list of T per entity, held as a component: an inventory, a path, the hits of this tick.

public struct DynamicBuffer<T> : IComponent, ITrackChanges

A list of T per entity, held as a component: an inventory, a path, the hits of this tick. Writes go through a ref to the component (ref parameters of [ForEach] methods and jobs, Entity.Get), so they are tracked like any write of an ITrackChanges component and [Changed<DynamicBuffer<T>>] selects the entities whose list changed. Through in or Entity.Read the list is read-only: the mutating methods (DynamicBufferExtensions) take ref this, so a write through a read-only reference does not compile. Snapshots copy the elements (World.Capture); a moved row keeps its list. Adding within the capacity allocates nothing.

Remarks

A new DynamicBuffer<T>() holds no list: each entity's list is made by its first write (reserve room with DynamicBufferExtensions.EnsureCapacity), so one value can create many entities. The list lives in an object the component refers to, and a copy of the component would refer to the same list: the analyzer rejects copies (EECS012), reach the list through the entity.

Properties

Capacity

public readonly int Capacity { get; }

The number of elements the list holds before it grows.

Complexity (API table): O(1)

Count

public readonly int Count { get; }

The number of elements.

Complexity (API table): O(1)

Indexers

this[]

public readonly ref readonly T this[int index] { get; }

The element at index, read-only (write through DynamicBufferExtensions.AsSpan).

Methods

AsReadOnlySpan

public readonly ReadOnlySpan<T> AsReadOnlySpan();

The elements, read-only.

Complexity (API table): O(1)

GetEnumerator

public readonly ReadOnlySpan<T>.Enumerator GetEnumerator();

Enumerates the elements (read-only, no allocation).

Complexity (API table): O(1)

Edit on GitHub

Last updated on

How is this guide?

On this page