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
worldIWorldThe world the entity belongs to.
entityEntityThe entity receiving the component.
componentTThe component data being added.
Returns
- bool
trueif validation passes;falseotherwise.
Type Parameters
TThe 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.