# AddComponent

> Adds a component to an entity.

## Definition

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

## AddComponent(Entity, ComponentType)

Adds a component to an entity.

```csharp
public bool AddComponent(Entity entity, ComponentType componentType)
```

### Parameters

**** (\[Entity]\(/engine/7000.0/script-reference/unity/entities/entity)): The Entity.**** (\[ComponentType]\(/engine/7000.0/script-reference/unity/entities/componenttype)): The type of component to add.

### Returns

| Type                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | If the component was successfully added to the entity. |

### Remarks

Can add any kind of component except chunk components. For chunk components, use [EntityManager.AddChunkComponentData](/engine/7000.0/script-reference/unity/entities/entitymanager/addchunkcomponentdata.md).

Adding a component changes the entity's archetype and results in the entity being moved to a different chunk.

The added component has the default values for the type.

If the [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) object refers to an entity that already has the specified [ComponentType](/engine/7000.0/script-reference/unity/entities/componenttype.md), the function returns false without performing any modifications.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(SystemHandle, ComponentType)

Adds a component to an entity associated with a system.

```csharp
public bool AddComponent(SystemHandle system, ComponentType componentType)
```

### Parameters

**** (\[SystemHandle]\(/engine/7000.0/script-reference/unity/entities/systemhandle)): The system handle.**** (\[ComponentType]\(/engine/7000.0/script-reference/unity/entities/componenttype)): The type of component to add.

### Returns

| Type                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | If the component was successfully added to the entity. |

### Remarks

Can add any kind of component except chunk components. For chunk components, use [EntityManager.AddChunkComponentData](/engine/7000.0/script-reference/unity/entities/entitymanager/addchunkcomponentdata.md).

Adding a component changes the entity's archetype and results in the entity being moved to a different chunk.

The added component has the default values for the type.

If the [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) object refers to an entity that already has the specified [ComponentType](/engine/7000.0/script-reference/unity/entities/componenttype.md), the function returns false without performing any modifications.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent\<T>(Entity)

Adds a component to an entity.

```csharp
public bool AddComponent<T>(Entity entity)
```

### Parameters

**** (\[Entity]\(/engine/7000.0/script-reference/unity/entities/entity)): The Entity.

### Returns

| Type                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | If the component was successfully added to the entity. |

### Remarks

Can add any kind of component except chunk components. For chunk components, use [EntityManager.AddChunkComponentData](/engine/7000.0/script-reference/unity/entities/entitymanager/addchunkcomponentdata.md).

Adding a component changes the entity's archetype and results in the entity being moved to a different chunk.

The added component has the default values for the type.

If the [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) object refers to an entity that already has the specified [ComponentType](/engine/7000.0/script-reference/unity/entities/componenttype.md), the function returns false without performing any modifications.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before addting the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent\<T>(SystemHandle)

Adds a component to an entity associated with a system.

```csharp
public bool AddComponent<T>(SystemHandle system)
```

### Parameters

**** (\[SystemHandle]\(/engine/7000.0/script-reference/unity/entities/systemhandle)): The system handle.

### Returns

| Type                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | If the component was successfully added to the entity. |

### Remarks

Can add any kind of component except chunk components. For chunk components, use [EntityManager.AddChunkComponentData](/engine/7000.0/script-reference/unity/entities/entitymanager/addchunkcomponentdata.md).

Adding a component changes the entity's archetype and results in the entity being moved to a different chunk.

The added component has the default values for the type.

If the [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) object refers to an entity that already has the specified [ComponentType](/engine/7000.0/script-reference/unity/entities/componenttype.md), the function returns false without performing any modifications.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before addting the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(EntityQuery, ComponentType)

Adds a component to a set of entities defined by a EntityQuery.

```csharp
public void AddComponent(EntityQuery entityQuery, ComponentType componentType)
```

### Parameters

**** (\[EntityQuery]\(/engine/7000.0/script-reference/unity/entities/entityquery)): The EntityQuery defining the entities to modify.**** (\[ComponentType]\(/engine/7000.0/script-reference/unity/entities/componenttype)): The type of component to add.

### Remarks

Can add any kind of component.

Adding a component changes an entity's archetype and results in the entity being moved to a different chunk.

The added components have the default values for the type.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before addting the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(EntityQuery, ComponentTypeSet)

Adds components to a set of entities defined by a EntityQuery.

```csharp
public void AddComponent(EntityQuery entityQuery, in ComponentTypeSet componentTypeSet)
```

### Parameters

**** (\[EntityQuery]\(/engine/7000.0/script-reference/unity/entities/entityquery)): The EntityQuery defining the entities to modify.**** (\[ComponentTypeSet]\(/engine/7000.0/script-reference/unity/entities/componenttypeset)): The type of components to add.

### Remarks

You can use this method to add a component to an Entity.

The added components have the default values for the type.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before addting the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent\<T>(EntityQuery)

Adds a component to a set of entities defined by a EntityQuery.

```csharp
public void AddComponent<T>(EntityQuery entityQuery)
```

### Parameters

**** (\[EntityQuery]\(/engine/7000.0/script-reference/unity/entities/entityquery)): The EntityQuery defining the entities to modify.

### Remarks

Can add any kind of component except chunk components.

Adding a component changes an entity's archetype and results in the entity being moved to a different chunk.

The added components have the default values for the type.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(NativeArray\<Entity>, ComponentType)

Adds a component to a set of entities.

```csharp
public void AddComponent(NativeArray<Entity> entities, ComponentType componentType)
```

### Parameters

**** (\[NativeArray\<Entity>]\(/engine/7000.0/script-reference/unity/collections/nativearray1)): An array of Entity objects.**** (\[ComponentType]\(/engine/7000.0/script-reference/unity/entities/componenttype)): The type of component to add.

### Remarks

Can add any kind of component except chunk components.

Adding a component changes an entity's archetype and results in the entity being moved to a different chunk.

The added components have the default values for the type.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before creating the chunk. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(NativeArray\<Entity>, ComponentTypeSet)

Adds components to a specified collection of entities.

```csharp
public void AddComponent(NativeArray<Entity> entities, in ComponentTypeSet componentTypeSet)
```

### Parameters

**** (\[NativeArray\<Entity>]\(/engine/7000.0/script-reference/unity/collections/nativearray1)): The collection of entities to modify.**** (\[ComponentTypeSet]\(/engine/7000.0/script-reference/unity/entities/componenttypeset)): The type of components to add.

### Remarks

You can use this method to add a component to an Entity.

The added components have the default values for the type.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent\<T>(NativeArray\<Entity>)

Adds a component to a set of entities.

```csharp
public void AddComponent<T>(NativeArray<Entity> entities)
```

### Parameters

**** (\[NativeArray\<Entity>]\(/engine/7000.0/script-reference/unity/collections/nativearray1)): An array of Entity objects.

### Remarks

Can add any kind of component.

Adding a component changes an entity's archetype and results in the entity being moved to a different chunk.

The added components have the default values for the type.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(SystemHandle, ComponentTypeSet)

Adds a set of component to an entity associated with a system.

```csharp
public void AddComponent(SystemHandle system, in ComponentTypeSet componentTypeSet)
```

### Parameters

**** (\[SystemHandle]\(/engine/7000.0/script-reference/unity/entities/systemhandle)): The system handle.**** (\[ComponentTypeSet]\(/engine/7000.0/script-reference/unity/entities/componenttypeset)): The types of components to add.

### Remarks

You can use this method to add a component to an Entity.

Adding components changes the entity's archetype and results in the entity being moved to a different chunk.

The added components have the default values for the type.

If the [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) object refers to an entity that has been destroyed, this function throws an InvalidOperationException exception.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before setting the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.

## AddComponent(Entity, ComponentTypeSet)

Adds a set of component to an entity.

```csharp
public void AddComponent(Entity entity, in ComponentTypeSet componentTypeSet)
```

### Parameters

**** (\[Entity]\(/engine/7000.0/script-reference/unity/entities/entity)): The entity to modify.**** (\[ComponentTypeSet]\(/engine/7000.0/script-reference/unity/entities/componenttypeset)): The types of components to add.

### Remarks

You can use this method to add a component to an Entity.

Adding components changes the entity's archetype and results in the entity being moved to a different chunk.

The added components have the default values for the type.

If the [Entity](/engine/7000.0/script-reference/unity/entities/entity.md) object refers to an entity that has been destroyed, this function throws an InvalidOperationException exception.

**Important:** This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before adding the component. No additional jobs can start before the method is finished. A sync point can cause a drop in performance because the ECS framework might not be able to use the processing power of all available cores.
