• Studio

  • Bots

  • Web API

  • Designer Resources

  • Host Resources

  • Material

    Inherits from: Object

    Imagine your game's 3D models as a stage, the Material class in Unity is the set designer, impacting the look and feel of the stage by determining how light interacts with the models. It influences their appearance, creating the essential visual ambiance of your game world.

    This class enables you to manipulate properties of materials used in rendering both 2D and 3D graphics. Whether it's to give a shiny metallic texture to a robot, a semi-transparent glaze to a ghostly apparition, or make a surface react to light in a specific way, the Material class aids in achieving these visual effects.

    Being a fundamental part of shader programming - the magic behind the colors, lighting effects, and textures in your game, the Material class is an indispensable tool in Unity. To have a comprehensive understanding of how to leverage it to enrich the aesthetics of your game environment, the official Unity Material Documentation is your go-to guide.

    Properties

    The 'color' property allows to set or retrieve the main color of the material. Changing this property can drastically affect the look of the rendered object. Further information can be found in Unity's Material.color Documentation.

    'mainTexture' property is used to apply or get the primary texture of the material. It allows to give detail to a GameObject by applying images to it. Explore more about this property in Unity's Material.mainTexture Documentation.

    The 'mainTextureOffset' attribute allows to adjust the placement of the primary texture on the rendered object. It can be used to create various visual effects. More information can be found in Unity's Material.mainTextureOffset Documentation.

    The 'mainTextureScale' property adjusts the size of the primary texture on the object, allowing for shrinking or stretching of the texture. More details in Unity's Material.mainTextureScale Documentation.

    The 'renderQueue' property allows adjusting the place of the material in the renderer's queue. Manipulating this property can result in some objects rendering in front of or behind others. Learn more by consulting Unity's Material.renderQueue Documentation.

    The 'doubleSidedGI' property enables or disables the illumination of the back-faces of the Game object, impacting how light is reflected in the scene. You can learn more Indirect lighting details in Unity's Material.doubleSidedGI Documentation.

    The 'enableInstancing' property when set to true, instructs Unity to use GPU instancing. This can provide a performance boost when drawing many identical geometries that share the same material. More information in Unity's Material.enableInstancing Documentation.

    passCount

    number

    The 'passCount' property gives the number of SubShader rendering passes in this material. Useful for fine grained control over complex shaders and rendering techniques. More info in Unity's Material.passCount Documentation.

    Methods

    The 'HasProperty' method checks whether the material has a property with a given name. This can be useful to prevent errors before trying to set or get a property. Learn more by checking Unity's Material.HasProperty Documentation.

    Parameters

    nameID

    number

    The identifier for the property you are checking for.

    Returns

    boolean

    Returns true if the property exists; otherwise, false.

    The 'HasFloat' method checks if the material has a specific float property. This is useful to prevent errors before attempting to access a float property. More details can be obtained from Unity's Material.HasFloat Documentation.

    Parameters

    name

    string

    The name of the float property to check.

    Returns

    boolean

    Returns true if the float property exists; otherwise, false.

    'HasInt' method checks whether the material has a specific integer property. This is useful when working with a custom shader that may or may not have specific properties. For more extensive information, visit Unity's Material.HasInt Documentation.

    Parameters

    name

    string

    The name of the integer property to check.

    Returns

    boolean

    Returns true if the integer property exists; otherwise, false.

    The 'HasInteger' method checks if the material has a specific integer property. This is useful when dealing with custom shaders that may or may not have specific properties. To learn more about this method, check Unity's Material.HasInteger Documentation.

    Parameters

    name

    string

    The name for the integer property to check.

    Returns

    boolean

    Returns true if the integer property exists; otherwise, false.

    'HasTexture' is a method that checks if the material has a specific texture property. This is handy to avoid errors when trying to access a texture property. More information can be found in Unity's Material.HasTexture Documentation.

    Parameters

    name

    string

    The name of the texture property to check.

    Returns

    boolean

    Returns true if the texture property exists; otherwise, false.

    The 'HasMatrix' method checks if the material has a specific matrix property. It's useful in preventing errors when trying to access a matrix property. To learn more, refer to Unity's Material.HasMatrix Documentation.

    Parameters

    name

    string

    The name of the matrix property to check.

    Returns

    boolean

    Returns true if the matrix property exists; otherwise, false.

    'HasVector' method checks if a specific vector property exists in the material. This can help in preventing errors when trying to access this property. More information can be found in Unity's Material.HasVector Documentation.

    Parameters

    name

    string

    The name of the vector property to check.

    Returns

    boolean

    Returns true if the vector property exists; otherwise, false.

    The 'HasColor' method is used to check if the material has a certain color property. This is done before getting or setting a color property to avoid errors. Find out more about color properties in Unity's Material.HasColor Documentation.

    Parameters

    name

    string

    The name of the color property to check.

    Returns

    boolean

    Returns true if the color property exists; false otherwise.

    The 'HasBuffer' method verifies if the material has a particular buffer property. This is useful when dealing with advanced rendering techniques that involve ComputeBuffers or GraphicsBuffers. Learn more from Unity's Material.HasBuffer Documentation.

    Parameters

    name

    string

    The name of the buffer property to check.

    Returns

    boolean

    Returns true if the buffer property exists; false otherwise.

    The 'HasConstantBuffer' method checks if the material has a specific constant buffer property. This can be important in high-end graphics where constant buffers are used to hold resources for shaders. More info can be obtained from Unity's Material.HasConstantBuffer Documentation.

    Parameters

    name

    string

    The name of the constant buffer property to check.

    Returns

    boolean

    Returns true if the constant buffer property exists; false otherwise.

    The 'EnableKeyword' method allows you to enable a specific shader keyword for this material. This can be used for activating certain behavior of a multi-feature shader. You can find more information in Unity's Material.EnableKeyword Documentation.

    Parameters

    keyword

    string

    The keyword to enable for this material.

    Returns

    void

    'DisableKeyword' is a method that allows you to disable certain shader keywords on this material. This can be used to switch off specific features of a multi-purpose shader. To learn more, refer to Unity's Material.DisableKeyword Documentation.

    Parameters

    keyword

    string

    The keyword to disable for this material.

    Returns

    void

    The 'IsKeywordEnabled' method checks if a specific shader keyword is enabled for this material. This can be used to verify the state of a feature of a multi-function shader. Learn more by checking the Unity's Material.IsKeywordEnabled Documentation.

    Parameters

    keyword

    string

    The keyword to check for this material.

    Returns

    boolean

    Returns true if the keyword is enabled; false otherwise.

    The 'SetShaderPassEnabled' method enables or disables a specific Shader pass on the material. This offers more control over the rendering process, which can be useful for complex materials or advanced rendering techniques. For more information, see the Unity's Material.SetShaderPassEnabled Documentation.

    Parameters

    passName

    string

    The name of the Shader pass to enable or disable.

    enabled

    boolean

    Whether the Shader pass should be enabled.

    Returns

    void

    The 'GetShaderPassEnabled' method gets the status (enabled/disabled) of a specific Shader pass on the material. This can be used to check how the material is being drawn, which is helpful when understanding complex materials or rendering techniques. Instructions for how to use the method can be found in Unity's Material.GetShaderPassEnabled Documentation.

    Parameters

    passName

    string

    The name of the Shader pass whose status will be returned.

    Returns

    boolean

    Returns true if the Shader pass is enabled, false if it's not.

    The 'GetPassName' method fetches the name of a particular pass from a material. A pass in Unity represents a single rendering step, and knowing their names can be useful when dealing with complex rendering logic. Find out more from Unity's Material.GetPassName Documentation.

    Parameters

    pass

    number

    The index of the pass to fetch the name from.

    Returns

    string

    The name of the pass.

    The 'FindPass' method retrieves the index of a pass by its name. This can be helpful when dealing with complex rendering pipelines where specific passes need to be identified and modified. More details can be found in Unity's Material.FindPass Documentation.

    Parameters

    passName

    string

    The name of the pass to find the index of.

    Returns

    number

    The index of the pass, or -1 if the pass doesn't exist.

    The 'SetOverrideTag' method overrides or sets a shader tag for this material. Shader tags in Unity are used to determine how to render an object, and overriding them can help achieve unique rendering effects for particular materials. You can learn more in Unity's Material.SetOverrideTag Documentation.

    Parameters

    tag

    string

    The tag to be overridden in this material.

    val

    string

    The value to set for the overridden tag.

    Returns

    void

    The 'GetTag' method retrieves the value of a shader tag from this material, providing more control over the rendering process. If the specified tag does not exist, a fallback value can be provided. For more information, check Unity's Material.GetTag Documentation.

    Parameters

    tag

    string

    The name of the shader tag to retrieve.

    searchFallbacks

    boolean

    Whether to look in the shader's fallbacks if the tag isn't found.

    defaultValue

    string

    The value to return if the specified tag isn't found.

    Returns

    string

    The value of the shader tag if it exists; otherwise, the defaultValue.

    The 'Lerp' method linearly interpolates between two Materials based on t parameter and applies the result to this Material. It's useful to blend between different materials dynamically, creating a transition effect. More details are in Unity's Material.Lerp Documentation.

    Parameters

    The start Material for the Lerp operation.

    The end Material for the Lerp operation.

    t

    number

    The Lerp weighting factor.

    Returns

    void

    'SetPass' activates a given Shader Pass for rendering current object. It's used to set a particular pass in the material’s shader to the rendering hardware. More information can be found in Unity's Material.SetPass Documentation.

    Parameters

    pass

    number

    The index of the pass to set.

    Returns

    boolean

    If the shader or pass is not valid, this function will return false; otherwise, it returns true.

    The 'CopyPropertiesFromMaterial' method copies properties from specified material to current material. This is helpful when you need to create a new material with the same properties as an existing one. Find more details in Unity's Material.CopyPropertiesFromMaterial Documentation.

    Parameters

    The source material to copy properties from.

    Returns

    void

    'CopyMatchingPropertiesFromMaterial' copies properties from another material that match with properties of the current material. This can be useful for duplicating only the relevant properties from another material. Unity's Material.CopyMatchingPropertiesFromMaterial Documentation provides more information.

    Parameters

    The source material to copy matching properties from.

    Returns

    void

    The 'ComputeCRC' method computes a cyclic redundancy check value for the material. This can be useful for comparing materials or for caching materials without storing them entirely. More details can be found in Unity's Material.ComputeCRC Documentation.

    Returns

    number

    Returns the calculated CRC value.

    'SetInt' method sets an integer property in the material. This can be used to interact with integer properties defined in the shader used by the material. More information can be found in Unity's Material.SetInt Documentation.

    Parameters

    name

    string

    The name of the property to set.

    value

    number

    The integer value to set the property to.

    Returns

    void

    'SetFloat' is a method used to set a float property in the material. It is typically used to interact with float properties defined in the shader used by the material. Learn more about this method in Unity's Material.SetFloat Documentation.

    Parameters

    name

    string

    The name of the property to set.

    value

    number

    The float value to set the property to.

    Returns

    void

    The 'SetInteger' method is used to set an integer property in the material. It can be used to interact with integer properties defined in the shader used by the material. Detailed information can be found in Unity's Material.SetInteger Documentation.

    Parameters

    name

    string

    The name of the property to set.

    value

    number

    The integer value to set the property to.

    Returns

    void

    The 'SetColor' method sets a color property in the material. This can be used to change the color of the material at runtime, allowing for dynamic visual effects. Refer to Unity's Material.SetColor Documentation for more details.

    Parameters

    name

    string

    The name for the color property to set.

    value
    Color

    The color value to set the property to.

    Returns

    void

    The 'SetVector' method sets a Vector4 property in the material. This can be very useful when applying transformations or other operations that can be done through vector properties of a shader. Find more details in Unity's Material.SetVector Documentation.

    Parameters

    name

    string

    The name of the Vector4 property to set.

    value
    Vector4

    The Vector4 value to set the property to.

    Returns

    void

    'SetMatrix' is a method that sets a Matrix4x4 property in the material. This can be used to affect transformations or other matrix operations within the shader used by the material. For a better understanding, refer to Unity's Material.SetMatrix Documentation.

    Parameters

    name

    string

    The name of the Matrix4x4 property to set.

    The Matrix4x4 value to set the property to.

    Returns

    void

    The 'SetTexture' method assigns a texture to a named property within a shader. It can be used to dynamically change the textures used by a material at runtime. The details can be found in Unity's Material.SetTexture Documentation.

    Parameters

    name

    string

    The name of the texture property to set.

    value
    Texture

    The Texture object to use.

    Returns

    void

    The 'GetInt' method retrieves the integer value of a named property in a material. It is mainly used when we need a specific integer property for calculations or conditions. Refer to Unity's Material.GetInt Documentation for more information.

    Parameters

    name

    string

    The name of the integer property to retrieve.

    Returns

    number

    The integer value of the specified property.

    The 'GetFloat' method fetches the float value of a named property within a material. This method is often used when working with float properties of a shader that are needed for mathematical operations. You can find more details in Unity's Material.GetFloat Documentation.

    Parameters

    name

    string

    The name of the float property to retrieve.

    Returns

    number

    The float value of the given property.

    The 'GetInteger' method gets the integer value of a named property in a material. This can be useful when working with shader properties that represent quantifiable data or entries in an array. See Unity's Material.GetInteger Documentation for more information.

    Parameters

    name

    string

    The property name to retrieve the integer value from.

    Returns

    number

    The integer value of the specified property.

    The 'GetColor' method fetches the color value of a named property from a material. The retrieved color can be used in various ways such as coloring other elements or calculations affecting color data. More details are in Unity's Material.GetColor Documentation.

    Parameters

    name

    string

    The name of the property to retrieve the color from.

    Returns

    Color

    The Color value of the specified property.

    The 'GetVector' method retrieves the Vector4 value of a named property in a material. This can be useful when dealing with vector properties of a shader. You can learn more about it from Unity's Material.GetVector Documentation.

    Parameters

    name

    string

    The property name to retrieve the Vector4 value from.

    Returns

    Vector4

    The Vector4 value of the specified property.

    The 'GetMatrix' method fetches the Matrix4x4 value of a named property in a material. This can be useful when manipulating transformations or other matrix operations within the shader used by the material. For an expanded explanation, see Unity's Material.GetMatrix Documentation.

    Parameters

    name

    string

    The name of the Matrix4x4 property to retrieve.

    Returns

    Matrix4x4

    The Matrix4x4 value of the specified property.

    'GetTexture' is a method that retrieves the texture mapped to a named property within a material. This allows you to access and potentially change the texture used by a material at runtime. More information is available in Unity's Material.GetTexture Documentation.

    Parameters

    name

    string

    The name of the property to retrieve the texture from.

    Returns

    Texture

    The Texture object currently in use by the material.

    The 'SetTextureOffset' method adjusts the texture coordinates of a material, effectively shifting the texture. This can be useful for creating effects like scrolling textures. More information can be found in Unity's Material.SetTextureOffset Documentation.

    Parameters

    name

    string

    The property name to which Texture offset will be applied.

    value
    Vector2

    The amount of texture offset to apply.

    Returns

    void

    'SetTextureScale' adjusts the scaling of the texture coordinates of a material, effectively altering the tiling of the texture. This feature can be used for various visual effects, like magnifying or shrinking the appearance of a texture. Refer to Unity's Material.SetTextureScale Documentation.

    Parameters

    name

    string

    The property name to which Texture scaling will be applied.

    value
    Vector2

    The amount of texture scaling to apply.

    Returns

    void

    This method does not require a return value.

    The 'GetTextureOffset' method retrieves the current texture offset of a property. This can be used to ascertain the current texture offset applied to a material. More info can be found in Unity's Material.GetTextureOffset Documentation.

    Parameters

    name

    string

    The name of the property to get the texture offset from.

    Returns

    Vector2

    The current texture offset of the material's property.

    The 'GetTextureScale' method gets the current texture tiling of a property. This can be used in your project to determine the scaling factor applied to the texture of a material. See more in Unity's Material.GetTextureScale Documentation.

    Parameters

    name

    string

    The name of the property to get the texture scale from.

    Returns

    Vector2

    The current texture tiling of the material's property.

    Updated 4 months ago

    PocketWorlds Icon

    © 2024 Pocket Worlds. All rights reserved.