Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

EntityManager.CreateEntity

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public Entity CreateEntity(EntityArchetype archetype);

Parameters

Parameter Description
archetype The archetype for the new entity.

Returns

Entity The Entity object that you can use to access the entity.

Description

Creates an entity having the specified archetype.

The EntityManager creates the entity in the first available chunk with the matching archetype that has enough space.

Important: This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before creating the entity. 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.


Declaration

public Entity CreateEntity(params ComponentType[] types);

Parameters

Parameter Description
types The types of components to add to the new entity.

Returns

Entity The Entity object that you can use to access the entity.

Description

Creates an entity having components of the specified types.

The EntityManager creates the entity in the first available chunk with the matching archetype that has enough space.

Important: This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before creating the entity. 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.


Declaration

public Entity CreateEntity(ReadOnlySpan<ComponentType> types);

Parameters

Parameter Description
types The types of components to add to the new entity.

Returns

Entity The Entity object that you can use to access the entity.

Description

Creates an entity having components of the specified types.

The EntityManager creates the entity in the first available chunk with the matching archetype that has enough space.

Important: This method creates a sync point, which means that the EntityManager waits for all currently running jobs to complete before creating the entity. 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.


Declaration

public Entity CreateEntity();

Returns

Entity The Entity object that you can use to access the entity.

Description

Creates an entity with no components.

The EntityManager creates the entity in the first available chunk with the archetype having no components.

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.


Declaration

public void CreateEntity(EntityArchetype archetype, NativeArray<Entity> entities);

Parameters

Parameter Description
archetype The archetype defining the structure for the new entities.
entities An array to hold the Entity objects needed to access the new entities. The length of the array determines how many entities are created.

Description

Creates a set of entities of the specified archetype.

Fills the &lt;a href="https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1.html"&gt;NativeArray&lt;/a&gt; object assigned to the entities parameter with the Entity objects of the created entities. Each entity has the components specified by the EntityArchetype object assigned to the archetype parameter. The EntityManager adds these entities to the EntityManager.World entity list. Use the Entity objects in the array for further processing, such as setting the component values.


Declaration

public NativeArray<Entity> CreateEntity(EntityArchetype archetype, int entityCount, AllocatorHandle allocator);

Parameters

Parameter Description
archetype The archetype defining the structure for the new entities.
entityCount The number of entities to create with the specified archetype.
allocator How the created native array should be allocated.

Returns

NativeArray<Entity> A &lt;a href="https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1.html"&gt;NativeArray&lt;/a&gt; of entities with the given archetype.

Description

Creates a set of entities of the specified archetype.

Creates a &lt;a href="https://docs.unity3d.com/ScriptReference/Unity.Collections.NativeArray_1.html"&gt;NativeArray&lt;/a&gt; of entities, each of which has the components specified by the EntityArchetype object assigned to the archetype parameter. The EntityManager adds these entities to the EntityManager.World entity list.


Declaration

public void CreateEntity(EntityArchetype archetype, int entityCount);

Parameters

Parameter Description
archetype The archetype defining the structure for the new entities.
entityCount The number of entities to create with the specified archetype.

Description

Creates a set of entities of the specified archetype.

Unlike the other overloads, this does not create an array of Entity values. You don't always need the Entity value of a newly created entity because maybe you only need to access the entity through queries.