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

EntityManager.Instantiate

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 Instantiate(Entity srcEntity);

Parameters

Parameter Description
srcEntity The entity to clone.

Returns

Entity The Entity object for the new entity.

Description

Clones an entity.

The new entity has the same archetype and component values as the original; however, ICleanupComponentData and Prefab components are removed from the clone.

If the source entity was converted from a prefab and thus has a LinkedEntityGroup component, the entire group is cloned as a new set of entities. Components that are being cloned and contain references to entities that are also being cloned are properly remapped to the newly instantiated entities. 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 void Instantiate(Entity srcEntity, NativeArray<Entity> outputEntities);

Parameters

Parameter Description
srcEntity The entity to clone.
outputEntities An array to receive the Entity objects of the root entity in each clone. The length of this array determines the number of clones.

Description

Makes multiple clones of an entity.

The new entity has the same archetype and component values as the original, however cleanup and prefab tag components are removed from the clone.

If the source entity has a LinkedEntityGroup component, the entire group is cloned as a new set of entities. Entity references on components that are being cloned to entities inside the set are remapped to the instantiated entities.

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 NativeArray<Entity> Instantiate(Entity srcEntity, int instanceCount, AllocatorHandle allocator);

Parameters

Parameter Description
srcEntity The entity to clone.
instanceCount The number of entities to instantiate with the same components as the source entity.
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.

Description

Makes multiple clones of an entity.

The new entity has the same archetype and component values as the original, however cleanup and prefab tag components are removed from the clone.

If the source entity has a LinkedEntityGroup component, the entire group is cloned as a new set of entities. Entity references on components that are being cloned to entities inside the set are remapped to the instantiated entities.

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.


Obsolete This method will be removed in a future Entities release. If you wish to clone the full hierarchy of every entity in a given array, simply loop through the array to and invoke `EntityManager.Instantiate(Entity entity)` on each entity.

Declaration

public void Instantiate(NativeArray<Entity> srcEntities, NativeArray<Entity> outputEntities);

Parameters

Parameter Description
srcEntities The set of entities to clone
outputEntities the set of entities that were cloned. outputEntities.Length must match srcEntities.Length

Description

Clones a set of entities.

The new entity has the same archetype and component values as the original, however cleanup and prefab tag components are removed from the clone.

Entity references on components that are being cloned to entities inside the set are remapped to the instantiated entities. This method overload ignores the LinkedEntityGroup component, since the group of entities that will be cloned is passed explicitly.

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.