docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class StencilMaterial

    Dynamic material class makes it possible to create custom materials on the fly on a per-Graphic basis, and still have them get cleaned up correctly.

    Inheritance
    object
    StencilMaterial
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.UI
    Assembly: UnityEngine.UI.dll
    Syntax
    public static class StencilMaterial

    Methods

    Add(Material, int, StencilOp, CompareFunction, ColorWriteMask)

    Add a new material using the specified base and stencil ID.

    Declaration
    public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask)
    Parameters
    Type Name Description
    Material baseMat

    The base material.

    int stencilID

    Stencil reference value.

    StencilOp operation

    Stencil operation on pass.

    CompareFunction compareFunction

    Stencil comparison function.

    ColorWriteMask colorWriteMask

    Color channel write mask.

    Returns
    Type Description
    Material

    A material with the requested stencil settings.

    Add(Material, int, StencilOp, CompareFunction, ColorWriteMask, int, int)

    Add a new material using the specified base and stencil ID.

    Declaration
    public static Material Add(Material baseMat, int stencilID, StencilOp operation, CompareFunction compareFunction, ColorWriteMask colorWriteMask, int readMask, int writeMask)
    Parameters
    Type Name Description
    Material baseMat

    The base material.

    int stencilID

    Stencil reference value.

    StencilOp operation

    Stencil operation on pass.

    CompareFunction compareFunction

    Stencil comparison function.

    ColorWriteMask colorWriteMask

    Color channel write mask.

    int readMask

    Stencil read mask.

    int writeMask

    Stencil write mask.

    Returns
    Type Description
    Material

    A material with the requested stencil settings.

    ClearAll()

    Releases all cached stencil materials and clears the internal cache.

    Declaration
    public static void ClearAll()

    Remove(Material)

    Remove an existing material, automatically cleaning it up if it's no longer in use.

    Declaration
    public static void Remove(Material customMat)
    Parameters
    Type Name Description
    Material customMat

    The stencil material to release. Destroyed when reference count reaches zero.

    In This Article
    Back to top
    Copyright © 2026 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)