Skip to content

Game.Rendering.InstanceData

Assembly:
Assembly-CSharp (typical Unity project assembly; actual assembly may vary)

Namespace:
Game.Rendering

Type:
struct InstanceData

Base:
System.ValueType

Summary:
Lightweight container struct used to describe a single renderable instance in the game's rendering pipeline. It stores an Entity reference and small indices that identify which mesh group, mesh within that group, and tile variant to use for this instance. Commonly used as a CPU-side representation of per-instance metadata that is consumed by rendering code or converted into GPU instance buffers. {{ This struct is a plain value type (no Unity ECS interfaces implemented in the provided file). If the intent is to use it directly as a Unity ECS component you would normally implement IComponentData or use a DynamicBuffer/BlobAsset as appropriate. Also be aware of struct alignment and padding when sending this data to the GPU — consider explicit packing or matching GPU-side layout. }}


Fields

  • public Unity.Entities.Entity m_Entity
    {{ The ECS entity associated with this instance. This allows systems to look up additional data (transform, components) related to the instance. Note: Entity size/layout depends on the ECS version/target platform and must be considered when serializing this struct for GPU use. }}

  • public byte m_MeshGroup
    {{ Index of the mesh group the instance belongs to. Likely used to select a subset of meshes/materials in the renderer. Range and meaning are defined by the surrounding rendering/data pipeline. }}

  • public byte m_MeshIndex
    {{ Index of the specific mesh within the selected mesh group. Allows selecting different mesh variants (e.g., LODs or sub-meshes). }}

  • public byte m_TileIndex
    {{ Index selecting a tile or texture/atlas variant for the instance. Often used for choosing which tile artwork to apply. }}

Properties

  • None
    {{ This struct declares no properties. All data members are public fields. If you need encapsulation or computed values, consider adding properties or helper methods in a wrapper. }}

Constructors

  • public InstanceData()
    {{ Implicit default struct constructor (zero-initializes fields). For convenience you can create instances with field initializers, e.g. new InstanceData { m_Entity = entity, m_MeshGroup = 1, m_MeshIndex = 2, m_TileIndex = 0 }. If you need a custom constructor, add one explicitly in the source. }}

Methods

  • None
    {{ The struct defines no methods. Any utility functions (packing/unpacking, GPU conversion helpers, validation) should be implemented in helper classes or extension methods. }}

Usage Example

// Create and populate an array of InstanceData to feed into a renderer or convert to a GPU buffer
var instances = new InstanceData[3];

instances[0] = new InstanceData
{
    m_Entity = entity0,
    m_MeshGroup = 0,
    m_MeshIndex = 1,
    m_TileIndex = 2
};

instances[1] = new InstanceData
{
    m_Entity = entity1,
    m_MeshGroup = 0,
    m_MeshIndex = 2,
    m_TileIndex = 1
};

instances[2] = new InstanceData
{
    m_Entity = entity2,
    m_MeshGroup = 1,
    m_MeshIndex = 0,
    m_TileIndex = 0
};

// Further processing: convert to GPU-friendly layout, upload to a ComputeBuffer/StructuredBuffer,
// or use in a rendering system that maps these indices to meshes/materials.

Additional notes:
- If this struct's data is intended to be sent directly to the GPU, watch out for padding introduced by the Entity field and by byte alignment; you may prefer a compact GPU-side representation (e.g., ints/uints) and an explicit conversion step.
- If you want to attach this directly to ECS entities as a component, implement Unity.Entities.IComponentData or use a DynamicBuffer element depending on usage patterns.