# GetSharedComponentIndex

> Gets the index into the array of unique values for the specified shared component.

## Definition

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

## GetSharedComponentIndex\<T>(SharedComponentTypeHandle\<T>)

Gets the index into the array of unique values for the specified shared component.

```csharp
public readonly int GetSharedComponentIndex<T>(SharedComponentTypeHandle<T> chunkSharedComponentData) where T : struct, ISharedComponentData
```

### Parameters

**** (\[SharedComponentTypeHandle\<T>]\(/engine/7000.0/script-reference/unity/entities/sharedcomponenttypehandle1)): An object containing type and job safety information. To create this object, call [ComponentSystemBase.GetSharedComponentTypeHandle](/engine/7000.0/script-reference/unity/entities/componentsystembase/getsharedcomponenttypehandle.md). Pass the object to a job using a public field you define as part of the job struct.

### Returns

| Type                                                       | Description                                                                                    |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index value, or -1 if the chunk does not contain a shared component of the specified type. |

### Remarks

Because shared components can contain managed types, you can only access the value index of a shared component inside a job, not the value itself. The index value indexes the array returned by [EntityManager.GetAllUniqueSharedComponents](/engine/7000.0/script-reference/unity/entities/entitymanager/getalluniquesharedcomponents.md). If desired, you can create a native array that mirrors your unique value list, but which contains only unmanaged, blittable data and pass that into an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) job. The unique value list and a specific index is only valid until a structural change occurs.

## GetSharedComponentIndex\<T>(SharedComponentTypeHandle\<T>)

Gets the index into the array of unique values for the specified shared component.

```csharp
public readonly int GetSharedComponentIndex<T>(ref SharedComponentTypeHandle<T> chunkSharedComponentData) where T : struct, ISharedComponentData
```

### Parameters

**** (\[SharedComponentTypeHandle\<T>]\(/engine/7000.0/script-reference/unity/entities/sharedcomponenttypehandle1)): An object containing type and job safety information. To create this object, call [ComponentSystemBase.GetSharedComponentTypeHandle](/engine/7000.0/script-reference/unity/entities/componentsystembase/getsharedcomponenttypehandle.md). Pass the object to a job using a public field you define as part of the job struct.

### Returns

| Type                                                       | Description                                                                                    |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index value, or -1 if the chunk does not contain a shared component of the specified type. |

### Remarks

Because shared components can contain managed types, you can only access the value index of a shared component inside a job, not the value itself. The index value indexes the array returned by [EntityManager.GetAllUniqueSharedComponents](/engine/7000.0/script-reference/unity/entities/entitymanager/getalluniquesharedcomponents.md). If desired, you can create a native array that mirrors your unique value list, but which contains only unmanaged, blittable data and pass that into an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) job. The unique value list and a specific index is only valid until a structural change occurs.

## GetSharedComponentIndex(DynamicSharedComponentTypeHandle)

Gets the index into the array of unique values for the specified shared component.

```csharp
public readonly int GetSharedComponentIndex(ref DynamicSharedComponentTypeHandle typeHandle)
```

### Parameters

**** (\[DynamicSharedComponentTypeHandle]\(/engine/7000.0/script-reference/unity/entities/dynamicsharedcomponenttypehandle)): An object containing type and job safety information. To create this object, call [ComponentSystemBase.GetDynamicSharedComponentTypeHandle](/engine/7000.0/script-reference/unity/entities/componentsystembase/getdynamicsharedcomponenttypehandle.md).

### Returns

| Type                                                       | Description                                                                                    |
| ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The index value, or -1 if the chunk does not contain a shared component of the specified type. |

### Remarks

Because shared components can contain managed types, you can only access the value index of a shared component inside a job, not the value itself. The index value indexes the array returned by [EntityManager.GetAllUniqueSharedComponents](/engine/7000.0/script-reference/unity/entities/entitymanager/getalluniquesharedcomponents.md). If desired, you can create a native array that mirrors your unique value list, but which contains only unmanaged, blittable data and pass that into an [IJobChunk](/engine/7000.0/script-reference/unity/entities/ijobchunk.md) job. The unique value list and a specific index is only valid until a structural change occurs.
