Struct ComponentDataFromEntity<T>
A [NativeContainer] that provides access to all instances of components of type T, indexed by Entity.
Namespace: Unity.Entities
Syntax
[NativeContainer]
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 IJobEntity, Entities.Foreach and IJobEntityBatch). 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. |
TryGetComponent(Entity, out T) | Retrieves the component associated with the specified Entity, if it exists. Then reports if the instance still refers to a valid entity and that it has a component of type T. |