EasyEcs
API reference

Maybe<T>

An optional component of the entity a [ForEach] method visits: static void Regen(ref Health h, Maybe<Buff> buff) visits every entity with Health…

public readonly ref struct Maybe<T> where T : struct, IComponent

An optional component of the entity a [ForEach] method visits: static void Regen(ref Health h, Maybe<Buff> buff) visits every entity with Health, and Maybe.HasValue tells whether this one also has a Buff. One method instead of a With and a Without variant when the optional part is small. A method that changes no structure finds the column once per run of rows and tests a presence bit per row; one that changes structure looks the component up through each entity. Split the method in two with [With<T>] / [Without<T>] in the hottest loops (no test per row). A method that only reads Maybe.Value reads T; one that writes through it (assigns, increments, passes it by ref, calls a method on it) writes T, and a tracked component is stamped when present. Valid for the call it is passed to (a ref struct).

Constructors

Maybe

public Maybe(ref T value);

Wraps value, a null ref when the entity lacks the component.

Properties

HasValue

public bool HasValue { get; }

Whether the entity has the component.

Value

public ref T Value { get; }

The component by ref; throws when the entity lacks it (check Maybe.HasValue).

Edit on GitHub

Last updated on

How is this guide?

On this page