docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method CreateEntity

    CreateEntity(EntityArchetype)

    Records a command to create an entity with specified archetype.

    Declaration
    public Entity CreateEntity(EntityArchetype archetype)
    Parameters
    Type Name Description
    EntityArchetype archetype

    The archetype of the new entity.

    Returns
    Type Description
    Entity

    An entity that will be assigned a chunk when this EntityCommandBuffer is played back.

    Remarks

    At playback, this command throws an error if the archetype contains the Prefab tag.

    Exceptions
    Type Condition
    ArgumentException

    Throws if the archetype is null.

    NullReferenceException

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

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    CreateEntity()

    Records a command to create an entity with no components.

    Declaration
    public Entity CreateEntity()
    Returns
    Type Description
    Entity

    An entity that will be assigned a chunk when this EntityCommandBuffer is played back.

    Exceptions
    Type Condition
    NullReferenceException

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

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    CreateEntity(EntityArchetype, NativeArray<Entity>)

    Records a command to create an array of entities with specified archetype.

    Declaration
    public void CreateEntity(EntityArchetype archetype, NativeArray<Entity> entities)
    Parameters
    Type Name Description
    EntityArchetype archetype

    The archetype of the new entities.

    NativeArray<Entity> 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.

    Remarks

    At playback, the entities will be assigned a chunk. Additionally, this command throws an error if the archetype contains the Prefab tag.

    Exceptions
    Type Condition
    ArgumentException

    Throws if the archetype is null.

    NullReferenceException

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

    InvalidOperationException

    Throws if this EntityCommandBuffer has already been played back.

    CreateEntity(int, Allocator)

    Records a command to create "count" entities with no components.

    Declaration
    public NativeArray<Entity> CreateEntity(int count, Allocator allocator)
    Parameters
    Type Name Description
    int count
    Allocator allocator
    Returns
    Type Description
    NativeArray<Entity>

    A NativeArray of entities that are valid and will be assigned a chunk when the EntityCommandBuffer is played back.

    Exceptions
    Type Condition
    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)