docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method Instantiate

    Instantiate(Entity)

    Records a command to create an entity with specified entity prefab.

    Declaration
    public Entity Instantiate(Entity e)
    Parameters
    Type Name Description
    Entity e

    The entity prefab.

    Returns
    Type Description
    Entity

    The root entity of the instantiated prefab.

    Remarks

    An instantiated entity has the same components and component values as the prefab entity, minus the Prefab tag component. If the source entity was destroyed before playback, this command throws an error.

     The returned entity is the root of the instantiated prefab. It is valid for use in
     subsequent commands on this buffer, but has no chunk until the ECB has been played back <xref href="Unity.Entities.EntityCommandBuffer.Playback(Unity.Entities.EntityManager)" data-throw-if-not-resolved="false"></xref>.
     For a prefab with a <code>LinkedEntityGroup</code>, only the root is allocated at record
     time. The child entity IDs are only available via the root's <code>LinkedEntityGroup</code>
     buffer after playback.
    
    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if Entity e is null and if safety checks are enabled.

    NullReferenceException

    Throws if an Allocator was not passed in when the EntityCommandBuffer was created.

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    Instantiate(Entity, NativeArray<Entity>)

    Records a command to create a NativeArray of entities with specified entity prefab.

    Declaration
    public void Instantiate(Entity e, NativeArray<Entity> entities)
    Parameters
    Type Name Description
    Entity e

    The entity prefab.

    NativeArray<Entity> entities

    A NativeArray that receives the root entities of the instantiated prefabs.

    Remarks

    An instantiated entity has the same components and component values as the prefab entity, minus the Prefab tag component. If the source entity was destroyed before playback, this command throws an error.

     The filled entities are the roots of each instantiated prefab. They are valid for use
     in subsequent commands on this buffer, but have no chunk until the ECB has been played back <xref href="Unity.Entities.EntityCommandBuffer.Playback(Unity.Entities.EntityManager)" data-throw-if-not-resolved="false"></xref>.
     For a prefab with a <code>LinkedEntityGroup</code>, only the roots are allocated at record
     time. The child entity IDs are only available via each root's <code>LinkedEntityGroup</code>
     buffer after playback.
    
    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if Entity e is null and if safety checks are enabled.

    NullReferenceException

    Throws if an Allocator was not passed in when the EntityCommandBuffer was created.

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)