Table of Contents

Class RequiresComponentAttribute

Namespace
KeenEyes
Assembly
KeenEyes.Abstractions.dll

Specifies that a component requires another component to be present on the same entity.

[AttributeUsage(AttributeTargets.Struct, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
public sealed class RequiresComponentAttribute : Attribute
Inheritance
RequiresComponentAttribute
Inherited Members

Examples

// RigidBody requires Transform to be present
[Component]
[RequiresComponent(typeof(Transform))]
public partial struct RigidBody
{
    public float Mass;
    public float Drag;
}

// Sprite requires both Transform and Renderable
[Component]
[RequiresComponent(typeof(Transform))]
[RequiresComponent(typeof(Renderable))]
public partial struct Sprite
{
    public string TextureId;
}

Remarks

When validation is enabled, adding a component with this attribute will verify that all required components are already present on the entity. If a required component is missing, a ComponentValidationException is thrown.

Multiple RequiresComponentAttribute can be applied to the same component to express multiple dependencies. Each dependency is validated independently when the component is added - required components must already be present on the entity.

Note: Dependencies are checked directly, not transitively. If A requires B and B requires C, adding A only validates that B is present. To ensure C is also present, either add C explicitly or add a [RequiresComponent(typeof(C))] to A.

Constructors

RequiresComponentAttribute(Type)

Specifies that a component requires another component to be present on the same entity.

public RequiresComponentAttribute(Type requiredType)

Parameters

requiredType Type

The type of component that must be present on the entity.

Examples

// RigidBody requires Transform to be present
[Component]
[RequiresComponent(typeof(Transform))]
public partial struct RigidBody
{
    public float Mass;
    public float Drag;
}

// Sprite requires both Transform and Renderable
[Component]
[RequiresComponent(typeof(Transform))]
[RequiresComponent(typeof(Renderable))]
public partial struct Sprite
{
    public string TextureId;
}

Remarks

When validation is enabled, adding a component with this attribute will verify that all required components are already present on the entity. If a required component is missing, a ComponentValidationException is thrown.

Multiple RequiresComponentAttribute can be applied to the same component to express multiple dependencies. Each dependency is validated independently when the component is added - required components must already be present on the entity.

Note: Dependencies are checked directly, not transitively. If A requires B and B requires C, adding A only validates that B is present. To ensure C is also present, either add C explicitly or add a [RequiresComponent(typeof(C))] to A.

Exceptions

ArgumentNullException

Thrown when requiredType is null.

Properties

RequiredType

Gets the type of the required component.

public Type RequiredType { get; }

Property Value

Type

Exceptions

ArgumentNullException

Thrown when requiredType is null.