EntityBatch.md

July 25, 2024 · View on GitHub

Friflo.Engine.ECS

Friflo.Engine.ECS

EntityBatch Class

An entity batch is a container of component and tag commands that can be Apply()'ed to an entity.
It can be used on a single entity via Batch() or as a bulk operation an a set of entities.

public sealed class EntityBatch

Inheritance System.Object 🡒 EntityBatch

Remarks

Its purpose is to optimize add / remove component and tag changes on entities.
The same entity changes can be performed with the Entity methods using:
AddComponent<T>(), RemoveComponent<T>(), AddTag<TTag>() or RemoveTag<TTag>().
Each of these methods may cause a structural change which is a relative costly operation in comparison to others.
Using a batch minimize theses structural changes to one or none.

Bulk operation
To perform a batch on multiple entities you can use ApplyBatch(EntityBatch) for

Constructors
EntityBatch()Creates a batch that can be applied to a single entity or a set of entities using a bulk operation.
The created batch instance can be cached.
Properties
CommandCountReturn the number of commands stored in the EntityBatch.
Methods
Add<T>(T)Adds an add component command to the EntityBatch with the given component.
AddComponent<T>(T)Obsolete - use renamed method: Add<T>(T)
AddTag<T>()Adds an add tag command to the EntityBatch.
AddTags(Tags)Adds an add tags command to the EntityBatch adding the given tags.
Apply()Apply added batch commands to the entity the preceding Batch() operates.

Subsequent use of the batch throws BatchAlreadyAppliedException.
ApplyTo(Entity)Apply the batch commands to the given entity.
The stored batch commands are not cleared.
Clear()Clear all commands currently stored in the EntityBatch.
Disable()Disables an entity.
Disabled entities are not included query results. To include them use WithDisabled().
Enable()Enables an entity.
Enabled entities are included in query results.
Remove<T>()Adds a remove component command to the EntityBatch.
RemoveComponent<T>()Obsolete - use renamed method: Remove<T>()
RemoveTag<T>()Adds a remove tag command to the EntityBatch.
RemoveTags(Tags)Adds a remove tags command to the EntityBatch removing the given tags.
ToString()