docs.unity.cn
    Show / Hide Table of Contents

    Method SetComponentEnabled

    SetComponentEnabled(Entity, ComponentType, Boolean)

    Enable or disable ComponentType on the specified Entity.

    Declaration
    public void SetComponentEnabled(Entity entity, ComponentType componentType, bool value)
    Parameters
    Type Name Description
    Entity entity

    The entity whose component should be enabled or disabled.

    ComponentType componentType

    The component type to enable or disable. This type must implement the IEnableableComponent interface.

    Boolean value

    True if the specified component should be enabled, or false if it should be disabled.

    Remarks

    This operation does not cause a structural change, and does not affect the current value of the component.

    An entity with a disabled component will not match an EntityQuery that requires that component, and will match a query that excludes that component.

    To enable/disable components from a job, use SetComponentEnabled(Entity, Boolean). To enable/disable an entire Entity, use SetEnabled(Entity, Boolean) (which, unlike this function, does involve a structural change).

    Exceptions
    Type Condition
    ArgumentException

    The Entity does not exist.

    See Also
    IsComponentEnabled(Entity, ComponentType)
    SetComponentEnabled(Entity, Boolean)

    SetComponentEnabled<T>(Entity, Boolean)

    Enable or disable a ComponentType on the specified Entity.

    Declaration
    [GenerateTestsForBurstCompatibility(GenericTypeArguments = new Type[]{typeof(BurstCompatibleEnableableComponent)})]
    public void SetComponentEnabled<T>(Entity entity, bool value)
        where T : IEnableableComponent
    Parameters
    Type Name Description
    Entity entity

    The entity whose component should be enabled or disabled.

    Boolean value

    True if the specified component should be enabled, or false if it should be disabled.

    Type Parameters
    Name Description
    T

    The component type to enable or disable. This type must implement the IEnableableComponent interface.

    Remarks

    This operation does not cause a structural change, and does not affect the current value of the component.

    An entity with a disabled component will not match an EntityQuery that requires that component, and will match a query that excludes that component.

    To enable/disable components from a job, use SetComponentEnabled(Entity, Boolean). To enable/disable an entire Entity, use SetEnabled(Entity, Boolean) (which, unlike this function, does involve a structural change).

    Exceptions
    Type Condition
    ArgumentException

    The Entity does not exist.

    See Also
    IsComponentEnabled<T>(Entity)
    SetComponentEnabled(Entity, Boolean)
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Wednesday, June 21, 2023