docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct MaterialMeshInfo

    Represents which materials and meshes to use to render an entity.

    Implements
    IComponentData
    IQueryTypeParameter
    IEnableableComponent
    Namespace: Unity.Rendering
    Assembly: Unity.Entities.Graphics.dll
    Syntax
    public struct MaterialMeshInfo : IComponentData, IQueryTypeParameter, IEnableableComponent
    Remarks

    This struct supports both a serializable static encoding in which case Material and Mesh are array indices to some array (typically a RenderMeshArray), and direct use of runtime BatchRendererGroup BatchMaterialID / BatchMeshID values.

    Constructors

    MaterialMeshInfo(BatchMaterialID, BatchMeshID, ushort)

    Creates an instance of MaterialMeshInfo from material and mesh/sub-mesh IDs registered with EntitiesGraphicsSystem

    Declaration
    public MaterialMeshInfo(BatchMaterialID materialID, BatchMeshID meshID, ushort submeshIndex = 0)
    Parameters
    Type Name Description
    BatchMaterialID materialID

    The material ID from RegisterMaterial(Material).

    BatchMeshID meshID

    The mesh ID from RegisterMesh(Mesh).

    ushort submeshIndex

    An optional submesh ID.

    Fields

    Material

    The material ID.

    Declaration
    public int Material
    Field Value
    Type Description
    int
    Remarks

    The material ID can be one of the following:

    • A literal Material ID received from the RegisterMaterial API, encoded as a positive integer.
    • An array index to the RenderMeshArray shared component of the entity, encoded as a negative integer.

    Use the literal Material ID to change the material at runtime. Use the array index to store the material ID to disk during entity baking.

    Mesh

    The mesh ID.

    Declaration
    public int Mesh
    Field Value
    Type Description
    int

    Properties

    HasMaterialMeshIndexRange

    True if the MaterialMeshInfo is using a MaterialMeshIndex range.

    Declaration
    public bool HasMaterialMeshIndexRange { get; }
    Property Value
    Type Description
    bool

    MaterialID

    The material ID property.

    Declaration
    public BatchMaterialID MaterialID { get; set; }
    Property Value
    Type Description
    BatchMaterialID

    MaterialMeshIndexRange

    The MaterialMeshIndex range.

    Declaration
    public RangeInt MaterialMeshIndexRange { get; }
    Property Value
    Type Description
    RangeInt

    MeshID

    The mesh ID property.

    Declaration
    public BatchMeshID MeshID { get; set; }
    Property Value
    Type Description
    BatchMeshID

    SubMesh

    The sub-mesh ID.

    Declaration
    public ushort SubMesh { get; set; }
    Property Value
    Type Description
    ushort

    Methods

    ArrayIndexToStaticIndex(int)

    Converts the given array index (typically the index inside RenderMeshArray) into a negative number that denotes that array position.

    Declaration
    public static int ArrayIndexToStaticIndex(int index)
    Parameters
    Type Name Description
    int index

    The index to convert.

    Returns
    Type Description
    int

    Returns the converted index.

    FromMaterialMeshIndexRange(int, int)

    Creates an instance of MaterialMeshInfo from a range of material/mesh/submesh index in the corresponding RenderMeshArray.

    Declaration
    public static MaterialMeshInfo FromMaterialMeshIndexRange(int rangeStart, int rangeLength)
    Parameters
    Type Name Description
    int rangeStart

    The first index of the range in MaterialMeshIndices.

    int rangeLength

    The length of the range in MaterialMeshIndices.

    Returns
    Type Description
    MaterialMeshInfo

    FromRenderMeshArrayIndices(int, int, ushort)

    Creates an instance of MaterialMeshInfo from material and mesh/sub-mesh indices in the corresponding RenderMeshArray.

    Declaration
    public static MaterialMeshInfo FromRenderMeshArrayIndices(int materialIndexInRenderMeshArray, int meshIndexInRenderMeshArray, ushort submeshIndex = 0)
    Parameters
    Type Name Description
    int materialIndexInRenderMeshArray

    The material index in Materials.

    int meshIndexInRenderMeshArray

    The mesh index in Meshes.

    ushort submeshIndex

    An optional submesh ID.

    Returns
    Type Description
    MaterialMeshInfo

    Returns the MaterialMeshInfo instance that contains the material and mesh indices.

    StaticIndexToArrayIndex(int)

    Converts the given static index (a negative value) to a valid array index.

    Declaration
    public static int StaticIndexToArrayIndex(int staticIndex)
    Parameters
    Type Name Description
    int staticIndex

    The index to convert.

    Returns
    Type Description
    int

    Returns the converted index.

    Implements

    IComponentData
    IQueryTypeParameter
    IEnableableComponent
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)