Skip to content

Game.Prefabs.BrushCell

Assembly:
{{ The source file is located under the game's Game assembly / project. If you have a specific compiled assembly name for your mod or the game's assemblies, substitute it here. }}
Namespace: Game.Prefabs

Type:
struct

Base:
Unity.Entities.IBufferElementData

Summary:
BrushCell is an ECS buffer element type intended to represent a single cell (or sample) for a brush prefab/painting system. It is a simple, blittable struct containing a single float field m_Opacity which typically represents the opacity/strength of the brush at that cell. The struct is annotated with InternalBufferCapacity(0), meaning no space is reserved inside the entity for the buffer — buffer elements will be stored in dynamic memory and use an external buffer when added to an entity.


Fields

  • public float m_Opacity
    Represents the opacity (or strength) value for this brush cell. Typical usage is a normalized value, e.g., in the range 0.0 — 1.0, where 0 is transparent/no effect and 1 is fully applied. Being a plain float keeps the element blittable and efficient for ECS operations.

Properties

  • None

Constructors

  • Default value-type constructor (implicit)
    Value types have an implicit default constructor; you can create instances with new BrushCell { m_Opacity = value } or default(BrushCell).

Methods

  • None (no methods defined on this struct)

Notes and Implementation Details

  • The struct implements IBufferElementData, so it is intended to be used with DynamicBuffer on Entities.
  • The [InternalBufferCapacity(0)] attribute sets the internal buffer capacity to 0. This means the entity will not reserve inline (fast-path) storage for buffer elements; elements will be allocated externally. Use a non-zero capacity if you expect a small fixed number of elements and want to avoid heap allocations.
  • Ensure the element remains blittable (no managed/reference types) for best performance in Jobs and Burst-compiled systems.
  • Common patterns: storing brush samples in an entity buffer for later processing, sampling opacity values and applying them in a job that writes to tile or terrain data.

Usage Example

// Example inside a SystemBase or ComponentSystem:
// Add a BrushCell buffer to an entity and populate it.

Entity e = entityManager.CreateEntity(); // or obtain an existing entity

// Add the dynamic buffer (if not already present)
var buffer = entityManager.AddBuffer<BrushCell>(e);

// Add brush cells
buffer.Add(new BrushCell { m_Opacity = 1.0f });
buffer.Add(new BrushCell { m_Opacity = 0.5f });
buffer.Add(new BrushCell { m_Opacity = 0.25f });

// Alternatively, in SystemBase:
Entities.ForEach((Entity ent, int entityInQueryIndex, ref SomeBrushTag tag) =>
{
    var buf = EntityManager.GetBuffer<BrushCell>(ent);
    buf.Clear();
    buf.Add(new BrushCell { m_Opacity = 0.8f });
}).WithoutBurst().Run();

If you expect a small fixed number of cells and want faster access without external allocations, change the attribute:

[InternalBufferCapacity(8)]
public struct BrushCell : IBufferElementData
{
    public float m_Opacity;
}

This will reserve inline storage for up to 8 elements on the entity, reducing allocations for small buffers.