Game.Areas.Batch
Assembly:
Assembly-CSharp
Namespace:
Game.Areas
Type:
struct
Base:
IComponentData, IQueryTypeParameter, IEmptySerializable
Summary:
Represents a per-entity batch descriptor used by the game's area/batching systems. This struct holds low-level allocation and bookkeeping information for a single batch (allocation block, size, indices and visible item count). It is a pure value-type component intended to be attached to ECS entities that participate in area batching/visibility systems. As a component it must remain blittable and care must be taken when managing the NativeHeapBlock memory referenced by this struct.
Fields
-
public Colossal.Collections.NativeHeapBlock m_BatchAllocation
Native heap allocation block that backs the batch's raw data. This typically refers to a region of unmanaged memory used for storing per-batch vertex/index/instance data or other runtime buffers. The lifetime and disposal of this block must be managed by the owning system — the ECS will not automatically free internal memory held by this struct. -
public int m_AllocatedSize
The size (in bytes or elements, depending on how the allocation is used) currently allocated for m_BatchAllocation. Use this to determine whether the allocation is large enough for intended writes; if not, the allocation should be resized/replaced by the owning system. -
public int m_BatchIndex
Index of this batch within the parent area or batch collection. Used as an identifier when indexing per-area/batch arrays or metadata structures. -
public int m_VisibleCount
Number of visible items (instances/objects) currently counted for this batch. This is typically maintained by the visibility/batching system each frame or during culling updates. -
public int m_MetaIndex
Index into a metadata table or array for additional batch metadata. This can be used to look up per-batch material, LOD, or other auxiliary information.
Properties
- None. This type exposes raw public fields to be used directly by systems operating on the component.
Constructors
public Batch()
Default (parameterless) struct constructor. When added to an entity without explicit initialization, all fields will be zero/default (m_BatchAllocation will be default/empty). Always initialize m_BatchAllocation and m_AllocatedSize explicitly before writing into the memory referenced by m_BatchAllocation to avoid invalid memory access.
Methods
- None. This is a plain data container component (no methods defined). Allocation, resizing, disposal, and updates are expected to be handled by the systems that create and mutate this component.
Usage Example
// Example: creating and initializing a Batch component in a system
public partial class BatchSetupSystem : SystemBase
{
protected override void OnCreate()
{
base.OnCreate();
// Any one-time setup…
}
protected override void OnUpdate()
{
var em = World.EntityManager;
// Create an entity and add a Batch component (example)
var archetype = em.CreateArchetype(typeof(Game.Areas.Batch));
var e = em.CreateEntity(archetype);
// Prepare a NativeHeapBlock via Colossal.Collections API (pseudo-code)
Colossal.Collections.NativeHeapBlock heapBlock = Colossal.Collections.NativeHeapBlock.Allocate(1024);
var batch = new Game.Areas.Batch
{
m_BatchAllocation = heapBlock,
m_AllocatedSize = 1024,
m_BatchIndex = 0,
m_VisibleCount = 0,
m_MetaIndex = -1
};
em.SetComponentData(e, batch);
// IMPORTANT: manage heapBlock lifetime carefully.
// The system that owns the allocation must free/resize it when appropriate.
}
protected override void OnDestroy()
{
// If this system owned any NativeHeapBlock instances, ensure they are freed here.
base.OnDestroy();
}
}
Additional notes and best practices: - Because this component contains a NativeHeapBlock (unmanaged memory), ensure there is a clear ownership and disposal strategy to avoid memory leaks. The ECS will not automatically free memory referenced by fields inside IComponentData. - This struct implements IQueryTypeParameter and IEmptySerializable: it is intended to be usable in ECS queries and supports the game's custom serialization path. When persisting/loading, follow the game's serialization conventions for NativeHeapBlock contents. - Avoid storing managed references inside components. Keep this component strictly as unmanaged/blittable data for compatibility with Unity's DOTS and Jobs systems.