Struct EntityCommandBuffer | Entities | 0.16.0-preview.21
docs.unity3d.com
    Show / Hide Table of Contents

    Struct EntityCommandBuffer

    A thread-safe command buffer that can buffer commands that affect entities and components for later playback.

    Namespace: Unity.Entities
    Syntax
    [NativeContainer]
    [GenerateBurstMonoInterop("EntityCommandBuffer")]
    public struct EntityCommandBuffer : IDisposable

    Constructors

    EntityCommandBuffer(Allocator)

    Creates a new command buffer.

    Declaration
    public EntityCommandBuffer(Allocator label)
    Parameters
    Type Name Description
    Allocator label

    Memory allocator to use for chunks and data

    EntityCommandBuffer(Allocator, PlaybackPolicy)

    Creates a new command buffer.

    Declaration
    public EntityCommandBuffer(Allocator label, PlaybackPolicy playbackPolicy)
    Parameters
    Type Name Description
    Allocator label

    Memory allocator to use for chunks and data

    PlaybackPolicy playbackPolicy

    Specifies if the EntityCommandBuffer can be played a single time or more than once.

    Properties

    IsCreated

    Declaration
    public bool IsCreated { get; }
    Property Value
    Type Description
    Boolean

    MinimumChunkSize

    Allows controlling the size of chunks allocated from the temp job allocator to back the command buffer.

    Declaration
    public int MinimumChunkSize { get; set; }
    Property Value
    Type Description
    Int32

    ShouldPlayback

    Controls whether this command buffer should play back.

    Declaration
    public bool ShouldPlayback { get; set; }
    Property Value
    Type Description
    Boolean

    Methods

    AddBuffer<T>(Entity)

    Declaration
    public DynamicBuffer<T> AddBuffer<T>(Entity e)
        where T : struct, IBufferElementData
    Parameters
    Type Name Description
    Entity e
    Returns
    Type Description
    DynamicBuffer<T>
    Type Parameters
    Name Description
    T

    AddComponent(Entity, ComponentType)

    Declaration
    public void AddComponent(Entity e, ComponentType componentType)
    Parameters
    Type Name Description
    Entity e
    ComponentType componentType

    AddComponent(Entity, ComponentTypes)

    Records a command to add one or more components to an entity.

    Declaration
    public void AddComponent(Entity e, ComponentTypes componentTypes)
    Parameters
    Type Name Description
    Entity e

    The entity to get additional components.

    ComponentTypes componentTypes

    The types of components to add.

    AddComponent(EntityQuery, ComponentType)

    Records a command to add a component to all entities matching a query.

    Declaration
    public void AddComponent(EntityQuery entityQuery, ComponentType componentType)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities to add the component to.

    ComponentType componentType

    The type of component to add.

    Remarks

    The query is performed at playback time, not when the method is called.

    AddComponent(EntityQuery, ComponentTypes)

    Records a command to add one or more components to all entities matching a query.

    Declaration
    public void AddComponent(EntityQuery entityQuery, ComponentTypes types)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities get the added components.

    ComponentTypes types
    Remarks

    The query is performed at playback time, not when the method is called.

    AddComponent<T>(Entity)

    Declaration
    public void AddComponent<T>(Entity e)
        where T : struct, IComponentData
    Parameters
    Type Name Description
    Entity e
    Type Parameters
    Name Description
    T

    AddComponent<T>(Entity, T)

    Declaration
    public void AddComponent<T>(Entity e, T component)
        where T : struct, IComponentData
    Parameters
    Type Name Description
    Entity e
    T component
    Type Parameters
    Name Description
    T

    AddComponent<T>(EntityQuery)

    Records a command to add a component to all entities matching a query.

    Declaration
    public void AddComponent<T>(EntityQuery entityQuery)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities get the added component.

    Type Parameters
    Name Description
    T

    The type of component to add.

    Remarks

    The query is performed at playback time, not when the method is called.

    AddSharedComponent<T>(Entity, T)

    Declaration
    public void AddSharedComponent<T>(Entity e, T component)
        where T : struct, ISharedComponentData
    Parameters
    Type Name Description
    Entity e
    T component
    Type Parameters
    Name Description
    T

    AddSharedComponent<T>(EntityQuery, T)

    Records a command to add a shared component to all entities matching a query.

    Declaration
    public void AddSharedComponent<T>(EntityQuery entityQuery, T component)
        where T : struct, ISharedComponentData
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities to add the component value to.

    T component

    The component value to add.

    Type Parameters
    Name Description
    T
    Remarks

    The query is performed at playback time, not when the method is called. For entities matching the query which already have this component type, the value is updated.

    AppendToBuffer<T>(Entity, T)

    Appends a single element to the end of a dynamic buffer component.

    Declaration
    public void AppendToBuffer<T>(Entity e, T element)
        where T : struct, IBufferElementData
    Parameters
    Type Name Description
    Entity e

    The entity to which the dynamic buffer belongs.

    T element

    The new element to add to the DynamicBuffer<T> component.

    Type Parameters
    Name Description
    T

    The IBufferElementData type stored by the DynamicBuffer<T>.

    Remarks

    At Playback(EntityManager), this command throws an InvalidOperationException if the entity doesn't have a DynamicBuffer<T> component storing elements of type T.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if the entity does not have a DynamicBuffer<T> component storing elements of type T at the time the entity command buffer executes this append-to-buffer command.

    AsParallelWriter()

    Declaration
    public EntityCommandBuffer.ParallelWriter AsParallelWriter()
    Returns
    Type Description
    EntityCommandBuffer.ParallelWriter

    CreateEntity()

    Create an entity with no components.

    Declaration
    public Entity CreateEntity()
    Returns
    Type Description
    Entity

    CreateEntity(EntityArchetype)

    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

    DestroyEntity(Entity)

    Declaration
    public void DestroyEntity(Entity e)
    Parameters
    Type Name Description
    Entity e

    DestroyEntity(EntityQuery)

    Records a command to destroy all entities matching a query.

    Declaration
    public void DestroyEntity(EntityQuery entityQuery)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities from which the component is removed.

    Remarks

    The query is performed at playback time, not when the method is called.

    Dispose()

    Declaration
    public void Dispose()

    Instantiate(Entity)

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

    Playback(EntityManager)

    Play back all recorded operations against an entity manager.

    Declaration
    public void Playback(EntityManager mgr)
    Parameters
    Type Name Description
    EntityManager mgr

    The entity manager that will receive the operations

    Playback(ExclusiveEntityTransaction)

    Play back all recorded operations with an exclusive entity transaction. BeginExclusiveEntityTransaction().

    Declaration
    public void Playback(ExclusiveEntityTransaction mgr)
    Parameters
    Type Name Description
    ExclusiveEntityTransaction mgr

    The exclusive entity transaction that will process the operations

    RemoveComponent(Entity, ComponentType)

    Declaration
    public void RemoveComponent(Entity e, ComponentType componentType)
    Parameters
    Type Name Description
    Entity e
    ComponentType componentType

    RemoveComponent(Entity, ComponentTypes)

    Records a command to remove one or more components from an entity.

    Declaration
    public void RemoveComponent(Entity e, ComponentTypes componentTypes)
    Parameters
    Type Name Description
    Entity e

    The entity to have components removed.

    ComponentTypes componentTypes

    The types of components to remove.

    RemoveComponent(EntityQuery, ComponentType)

    Records a command to remove a component from all entities matching a query.

    Declaration
    public void RemoveComponent(EntityQuery entityQuery, ComponentType componentType)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities from which the component is removed.

    ComponentType componentType
    Remarks

    The query is performed at playback time, not when the method is called.

    RemoveComponent(EntityQuery, ComponentTypes)

    Records a command to remove one or more components from all entities matching a query.

    Declaration
    public void RemoveComponent(EntityQuery entityQuery, ComponentTypes componentTypes)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities to remove the components from.

    ComponentTypes componentTypes

    The types of components to remove.

    Remarks

    The query is performed at playback time, not when the method is called.

    RemoveComponent<T>(Entity)

    Declaration
    public void RemoveComponent<T>(Entity e)
    Parameters
    Type Name Description
    Entity e
    Type Parameters
    Name Description
    T

    RemoveComponent<T>(EntityQuery)

    Records a command to remove a component from all entities matching a query.

    Declaration
    public void RemoveComponent<T>(EntityQuery entityQuery)
    Parameters
    Type Name Description
    EntityQuery entityQuery

    The query specifying which entities from which the component is removed.

    Type Parameters
    Name Description
    T

    The type of component to remove.

    Remarks

    The query is performed at playback time, not when the method is called.

    SetBuffer<T>(Entity)

    Declaration
    public DynamicBuffer<T> SetBuffer<T>(Entity e)
        where T : struct, IBufferElementData
    Parameters
    Type Name Description
    Entity e
    Returns
    Type Description
    DynamicBuffer<T>
    Type Parameters
    Name Description
    T

    SetComponent<T>(Entity, T)

    Declaration
    public void SetComponent<T>(Entity e, T component)
        where T : struct, IComponentData
    Parameters
    Type Name Description
    Entity e
    T component
    Type Parameters
    Name Description
    T

    SetSharedComponent<T>(Entity, T)

    Declaration
    public void SetSharedComponent<T>(Entity e, T component)
        where T : struct, ISharedComponentData
    Parameters
    Type Name Description
    Entity e
    T component
    Type Parameters
    Name Description
    T

    Extension Methods

    EntityCommandBufferManagedComponentExtensions.AddComponent<T>(EntityCommandBuffer, Entity, T)
    EntityCommandBufferManagedComponentExtensions.AddComponent<T>(EntityCommandBuffer, Entity)
    EntityCommandBufferManagedComponentExtensions.SetComponent<T>(EntityCommandBuffer, Entity, T)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023