# ComponentLookup<T>

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

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Entities](/engine/7000.0/script-reference/unity/entities.md)
* **Assembly:** UnityEngine.EntitiesModule

```csharp
public struct ComponentLookup<T> where T : unmanaged, IComponentData
```

## Remarks

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

To get a ComponentLookup, call [ComponentSystemBase.GetComponentLookup](/engine/7000.0/script-reference/unity/entities/componentsystembase/getcomponentlookup.md).

Pass a ComponentLookup container to a job by defining a public field of the appropriate type in your IJob implementation. You can safely read from ComponentLookup in any job, but by default, you cannot write to components in the container in parallel jobs (including [IJobEntity](/engine/7000.0/script-reference/unity/entities/ijobentity.md), Entities.Foreach and [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md)). 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 ComponentLookup field definition in the job struct.

If you would like to access an entity's components outside of a job, consider using the [EntityManager](/engine/7000.0/script-reference/unity/entities/entitymanager.md) methods [EntityManager.GetComponentData](/engine/7000.0/script-reference/unity/entities/entitymanager/getcomponentdata.md) and [EntityManager.SetComponentData](/engine/7000.0/script-reference/unity/entities/entitymanager/setcomponentdata.md) instead, to avoid the overhead of creating a ComponentLookup object.

[NativeContainer]: https://docs.unity3d.com/ScriptReference/Unity.Collections.LowLevel.Unsafe.NativeContainerAttribute

[NativeDisableParallelForRestrictionAttribute]: https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeDisableParallelForRestrictionAttribute.html

## Properties

| Property                                                                            | Description                                                                                                                              |
| ----------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [this\[\]](/engine/7000.0/script-reference/unity/entities/componentlookup1/item.md) | Gets the [IComponentData](/engine/7000.0/script-reference/unity/entities/icomponentdata.md) instance of type T for the specified entity. |

## Methods

| Method                                                                                                                | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| --------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [DidChange](/engine/7000.0/script-reference/unity/entities/componentlookup1/didchange.md)                             | Reports whether any of IComponentData components of the type T, in the chunk containing the specified [Entity](/engine/7000.0/script-reference/unity/entities/entity.md), could have changed.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [EntityExists](/engine/7000.0/script-reference/unity/entities/componentlookup1/entityexists.md)                       | Reports whether the specified entity exists. Does not consider whether this component exists on the given entity.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [GetEnabledRefRO](/engine/7000.0/script-reference/unity/entities/componentlookup1/getenabledrefro.md)                 | Gets a safe reference to the component enabled state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [GetEnabledRefROOptional](/engine/7000.0/script-reference/unity/entities/componentlookup1/getenabledrefrooptional.md) | Gets a safe reference to the component enabled state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [GetEnabledRefRW](/engine/7000.0/script-reference/unity/entities/componentlookup1/getenabledrefrw.md)                 | Gets a safe reference to the component enabled state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [GetEnabledRefRWOptional](/engine/7000.0/script-reference/unity/entities/componentlookup1/getenabledrefrwoptional.md) | Gets a safe reference to the component enabled state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| [GetRefRO](/engine/7000.0/script-reference/unity/entities/componentlookup1/getrefro.md)                               | Gets a safe reference to the component data.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [GetRefRW](/engine/7000.0/script-reference/unity/entities/componentlookup1/getrefrw.md)                               | Gets a safe reference to the component data.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [HasComponent](/engine/7000.0/script-reference/unity/entities/componentlookup1/hascomponent.md)                       | Reports whether the specified [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) instance still refers to a valid entity and that it has a component of type T.                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [IsComponentEnabled](/engine/7000.0/script-reference/unity/entities/componentlookup1/iscomponentenabled.md)           | Checks whether the [IComponentData](/engine/7000.0/script-reference/unity/entities/icomponentdata.md) of type T is enabled on the specified [Entity](/engine/7000.0/script-reference/unity/entities/entity.md). For the purposes of EntityQuery matching, an entity with a disabled component will behave as if it does not have that component. The type T must implement the [IEnableableComponent](/engine/7000.0/script-reference/unity/entities/ienableablecomponent.md) interface.                                                                                                                         |
| [SetComponentEnabled](/engine/7000.0/script-reference/unity/entities/componentlookup1/setcomponentenabled.md)         | Enable or disable the [IComponentData](/engine/7000.0/script-reference/unity/entities/icomponentdata.md) of type T on the specified [Entity](/engine/7000.0/script-reference/unity/entities/entity.md). This operation does not cause a structural change (even if it occurs on a worker thread), or affect the value of the component. For the purposes of EntityQuery matching, an entity with a disabled component will behave as if it does not have that component. The type T must implement the [IEnableableComponent](/engine/7000.0/script-reference/unity/entities/ienableablecomponent.md) interface. |
| [TryGetComponent](/engine/7000.0/script-reference/unity/entities/componentlookup1/trygetcomponent.md)                 | Retrieves the component associated with the specified [Entity](/engine/7000.0/script-reference/unity/entities/entity.md), if it exists. Then reports if the instance still refers to a valid entity and that it has a component of type T.                                                                                                                                                                                                                                                                                                                                                                       |
| [TryGetRefRO](/engine/7000.0/script-reference/unity/entities/componentlookup1/trygetrefro.md)                         | Attempts to get a safe reference to the component data, failing gracefully if the component isn't present.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [TryGetRefRW](/engine/7000.0/script-reference/unity/entities/componentlookup1/trygetrefrw.md)                         | Attempts to get a safe reference to the component data, failing gracefully if the component isn't present.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Update](/engine/7000.0/script-reference/unity/entities/componentlookup1/update.md)                                   | When a ComponentLookup is cached by a system across multiple system updates, calling this function inside the system's OnUpdate() method performs the minimal incremental updates necessary to make the type handle safe to use.                                                                                                                                                                                                                                                                                                                                                                                 |
