Table of Contents

Delegate ComponentValidator<T>

Namespace
KeenEyes
Assembly
KeenEyes.Abstractions.dll

Delegate for custom component validation.

public delegate bool ComponentValidator<T>(IWorld world, Entity entity, T component) where T : struct, IComponent

Parameters

world IWorld

The world the entity belongs to.

entity Entity

The entity receiving the component.

component T

The component data being added.

Returns

bool

true if validation passes; false otherwise.

Type Parameters

T

The component type to validate.

Examples

// Validate that Health.Current never exceeds Health.Max
world.RegisterValidator<Health>((world, entity, health) =>
    health.Current >= 0 && health.Current <= health.Max && health.Max > 0);

Remarks

Custom validators are called when components are added to entities, after any attribute-based validation (like RequiresComponentAttribute).

If the validator returns false, a ComponentValidationException will be thrown, preventing the component from being added.