EasyEcs
API reference

ForEachAttribute

Runs a method of an EcsSystem (or a static method of any other type, through a generated entry point) for every entity matching its component parameters…

public sealed class ForEachAttribute : Attribute

Runs a method of an EcsSystem (or a static method of any other type, through a generated entry point) for every entity matching its component parameters (and the WithAttribute / WithoutAttribute / WithAnyAttribute filters), each update, after EcsSystem.OnUpdate, in declaration order.

Parameters: 1..9 components (ref to write, in to read; or Span<T> / ReadOnlySpan<T> for a batch method that receives runs of rows), singletons (ref / in), and optionally Entity and World. Static and instance methods are supported.

public class MovementSystem : EcsSystem
{
    [ForEach, Without<Frozen>]
    static void Move(ref Position p, in Velocity v) { p.X += v.X; p.Y += v.Y; }
}

EasyEcs.Generator compiles it to a struct job (IForEach, IForEachEntity or IForEachBatch): no delegate, no allocation, inlined.

Constructors

ForEachAttribute

public ForEachAttribute();

Properties

Parallel

public bool Parallel { get; init; }

Run chunks of the matching rows on several threads (World.ForEachParallel). The method must make no structural change, run per entity and write no singleton (EECS010); it pays off for heavy per-row work over tens of thousands of rows. Default false.

Edit on GitHub

Last updated on

How is this guide?

On this page