Skip to content

Game.Rendering.CustomBatch

Assembly: Game
Namespace: Game.Rendering

Type: class

Base: ManagedBatch

Summary:
CustomBatch is a managed rendering batch used by the modding/rendering system to represent a batch created from a source surface/mesh/material. It carries references to the original SurfaceAsset, source materials, fallback/loaded materials, the source mesh entities (per-instance and shared), mesh metadata (type/submesh index), and generation flags. It extends ManagedBatch to integrate with the rendering pipeline while preserving source-related information useful for swapping meshes or materials at runtime.


Fields

  • private SurfaceAsset <sourceSurface>k__BackingField
    Compiler-generated backing field for the public auto-property sourceSurface. Stores the SurfaceAsset that this batch was created from.

  • private Material <sourceMaterial>k__BackingField
    Compiler-generated backing field for the public auto-property sourceMaterial. Holds the original Material used by the source surface.

  • private Material <defaultMaterial>k__BackingField
    Compiler-generated backing field for the public auto-property defaultMaterial. Holds a fallback/default material used by the batch.

  • private Material <loadedMaterial>k__BackingField
    Compiler-generated backing field for the public auto-property loadedMaterial. Holds the material that was loaded/assigned for rendering (can differ from sourceMaterial).

  • private int <sourceSubMeshIndex>k__BackingField
    Compiler-generated backing field for the public auto-property sourceSubMeshIndex. Index of the sub-mesh in the source Mesh that this batch represents.

  • private Entity <sourceMeshEntity>k__BackingField
    Compiler-generated backing field for the public auto-property sourceMeshEntity. Entity reference to the mesh instance from which the batch was created.

  • private Entity <sharedMeshEntity>k__BackingField
    Compiler-generated backing field for the public auto-property sharedMeshEntity. Entity reference used when the mesh is shared among multiple batches/instances.

  • private BatchFlags <sourceFlags>k__BackingField
    Compiler-generated backing field for the public auto-property sourceFlags. Flags that describe generation/rendering options for the source.

  • private GeneratedType <generatedType>k__BackingField
    Compiler-generated backing field for the public auto-property generatedType. Indicates how/what type of geometry was generated.

  • private MeshType <sourceType>k__BackingField
    Compiler-generated backing field for the public auto-property sourceType. MeshType describing the kind of mesh (e.g., terrain, prop, building).

Note: The source code uses public auto-properties with private setters; the concrete private fields are compiler-generated backing fields as listed above.

Properties

  • public SurfaceAsset sourceSurface { get; private set }
    Reference to the SurfaceAsset that served as the source for this batch. Useful to query asset-level metadata or to map back to the original surface.

  • public Material sourceMaterial { get; private set }
    The original Material assigned to the source surface. Typically used for material comparisons or to restore original visuals.

  • public Material defaultMaterial { get; private set }
    A fallback/default material provided to ManagedBatch base. Used when the loaded or source material is unavailable.

  • public Material loadedMaterial { get; private set }
    The material instance that was ultimately loaded/used for rendering. Can be different from sourceMaterial (e.g., after replacements or runtime material modifications).

  • public int sourceSubMeshIndex { get; private set }
    Index of the sub-mesh within the source Mesh that this batch renders. Important when a Mesh contains multiple submeshes.

  • public Entity sourceMeshEntity { get; private set }
    Entity handle referencing the (possibly unique) mesh entity used when generating this batch.

  • public Entity sharedMeshEntity { get; private set }
    Entity handle referencing a shared mesh entity (if the mesh instance is shared across multiple batches).

  • public BatchFlags sourceFlags { get; private set }
    Flags describing generation/rendering behavior originating from the source (e.g., batching hints or dynamic/static flags).

  • public GeneratedType generatedType { get; private set }
    Indicates the generation type of the geometry (how it was generated by the pipeline).

  • public MeshType sourceType { get; private set }
    Describes the kind/category of the mesh content (used by rendering/processing logic).

Constructors

  • public CustomBatch(int groupIndex, int batchIndex, SurfaceAsset sourceSurface, Material sourceMaterial, Material defaultMaterial, Material loadedMaterial, Mesh mesh, Entity meshEntity, Entity sharedEntity, BatchFlags flags, GeneratedType generatedType, MeshType type, int subMeshIndex, MaterialPropertyBlock customProps)
    Creates a new CustomBatch instance.

Parameters: - groupIndex: Render/group index used by the ManagedBatch base. - batchIndex: Index of the batch within the group. - sourceSurface: SurfaceAsset that is the origin of this batch. - sourceMaterial: Original material from the source. - defaultMaterial: Default/fallback material to pass to the base ManagedBatch. - loadedMaterial: Material instance used for rendering (could be a variant of sourceMaterial). - mesh: The Mesh used for the ManagedBatch. - meshEntity: Entity representing the source mesh instance. - sharedEntity: Entity representing a shared mesh, if applicable. - flags: BatchFlags describing generation/rendering options from the source. - generatedType: GeneratedType describing how geometry was produced. - type: MeshType indicating the type/category of the mesh. - subMeshIndex: Sub-mesh index within the mesh that this batch renders. - customProps: MaterialPropertyBlock applied to the batch when rendering.

The constructor calls the ManagedBatch base constructor with groupIndex, batchIndex, defaultMaterial, mesh, a 0 (unknown vertex/instance parameter in code) and the supplied customProps, then stores all provided metadata on the instance.

Methods

  • public void ReplaceMesh(Entity oldMesh, Entity newMesh)
    Replaces references to a mesh entity within this batch. If either sourceMeshEntity or sharedMeshEntity equals oldMesh, that field is updated to newMesh. Use this to redirect the batch to a new mesh Entity without recreating the batch.

  • public override void Dispose()
    Overrides ManagedBatch.Dispose. The implementation currently calls base.Dispose() and does not add extra cleanup logic. If you attach external resources to CustomBatch instances, override or extend disposal logic accordingly.

Usage Example

// Example: creating and using a CustomBatch in a modded rendering context
SurfaceAsset surface = /* obtain SurfaceAsset */;
Material srcMat = /* obtain original Material */;
Material defaultMat = /* fallback Material */;
Material loadedMat = /* loaded/variant Material */;
Mesh mesh = /* mesh to render */;
Entity meshEntity = /* entity for this mesh */;
Entity sharedEntity = /* shared mesh entity or Entity.Null */;
BatchFlags flags = BatchFlags.None;
GeneratedType genType = GeneratedType.Custom;
MeshType meshType = MeshType.Static;
int subMeshIndex = 0;
MaterialPropertyBlock props = new MaterialPropertyBlock();

CustomBatch batch = new CustomBatch(
    groupIndex: 0,
    batchIndex: 0,
    sourceSurface: surface,
    sourceMaterial: srcMat,
    defaultMaterial: defaultMat,
    loadedMaterial: loadedMat,
    mesh: mesh,
    meshEntity: meshEntity,
    sharedEntity: sharedEntity,
    flags: flags,
    generatedType: genType,
    type: meshType,
    subMeshIndex: subMeshIndex,
    customProps: props
);

// Later, replace mesh entity if the mesh instance was swapped
Entity newMeshEntity = /* new mesh entity */;
batch.ReplaceMesh(meshEntity, newMeshEntity);

// Dispose when no longer needed (frees ManagedBatch resources)
batch.Dispose();