docs.unity3d.com
    Show / Hide Table of Contents

    Struct ComponentDataFromEntity<T>

    A [NativeContainer] that provides access to all instances of components of type T, indexed by Entity.

    Namespace: Unity.Entities
    Syntax
    public struct ComponentDataFromEntity<T>
        where T : struct, IComponentData
    Type Parameters
    Name Description
    T

    The type of IComponentData to access.

    Remarks

    ComponentDataFromEntity is a native container that provides array-like access to components of a specific type. You can use ComponentDataFromEntity to look up data associated with one entity while iterating over a different set of entities. For example, Unity.Transforms stores the Entity object of parent entities in a Parent component and looks up the parent's LocalToWorld matrix using ComponentDataFromEntity<LocalToWorld> when calculating the world positions of child entities.

    To get a ComponentDataFromEntity, call GetComponentDataFromEntity<T>(Boolean).

    Pass a ComponentDataFromEntity container to a job by defining a public field of the appropriate type in your IJob implementation. You can safely read from ComponentDataFromEntity in any job, but by default, you cannot write to components in the container in parallel jobs (including IJobForEach<T0> and IJobChunk). If you know that two instances of a parallel job can never write to the same index in the container, you can disable the restriction on parallel writing by adding NativeDisableParallelForRestrictionAttribute to the ComponentDataFromEntity field definition in the job struct.

    If you would like to access an entity's components outside of a job, consider using the EntityManager methods GetComponentData<T>(Entity) and SetComponentData<T>(Entity, T) instead, to avoid the overhead of creating a ComponentDataFromEntity object.

    Properties

    Name Description
    Item[Entity]

    Gets the IComponentData instance of type T for the specified entity.

    Methods

    Name Description
    DidChange(Entity, UInt32)

    Reports whether any of IComponentData components of the type T, in the chunk containing the specified Entity, could have changed.

    HasComponent(Entity)

    Reports whether the specified Entity instance still refers to a valid entity and that it has a component of type T.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023