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. Unity's Material Documentation
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. Unity's Material.color 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. 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. Unity's Material.enableInstancing Documentation
The '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. 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. 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. Unity's Material.mainTextureScale Documentation
The 'passCount' property gives the number of SubShader rendering passes in this material. Useful for fine grained control over complex shaders and rendering techniques. Unity's Material.passCount 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. Unity's Material.renderQueue Documentation
Methods
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. Unity's Material.ComputeCRC Documentation
Returns
Returns the calculated CRC value.
'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
Parameters
mat
The source material to copy matching properties from.
Returns
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. Unity's Material.CopyPropertiesFromMaterial Documentation
Parameters
mat
The source material to copy properties from.
Returns
Parameters
keyword
Returns
Parameters
keyword
Returns
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. Unity's Material.FindPass Documentation
Parameters
passName
The name of the pass.
Returns
The index of the pass, or -1 if the pass doesn't exist.
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. Unity's Material.GetColor Documentation
Parameters
nameID
Returns
The Color 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. Unity's Material.GetColor Documentation
Parameters
name
The name of the property to retrieve the color from.
Returns
The Color value of the specified property.
Parameters
nameID
Returns
Parameters
name
Returns
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. Unity's Material.GetFloat Documentation
Parameters
nameID
Returns
The float value of the given 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. Unity's Material.GetFloat Documentation
Parameters
name
The name of the float property to retrieve.
Returns
The float value of the given property.
Parameters
nameID
Returns
Parameters
name
Returns
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. Unity's Material.GetInteger Documentation
Parameters
nameID
Returns
The integer value of the specified 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. Unity's Material.GetInteger Documentation
Parameters
name
The property name to retrieve the integer value from.
Returns
The integer 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. Unity's Material.GetMatrix Documentation
Parameters
nameID
Returns
The Matrix4x4 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. Unity's Material.GetMatrix Documentation
Parameters
name
The name of the Matrix4x4 property to retrieve.
Returns
The Matrix4x4 value of the specified property.
Parameters
nameID
Returns
Parameters
name
Returns
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. Unity's Material.GetPassName Documentation
Parameters
pass
The index of the pass to fetch the name from.
Returns
The name of the pass.
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. Unity's Material.GetShaderPassEnabled Documentation
Parameters
passName
The name of the Shader pass whose status will be returned.
Returns
Returns true if the Shader pass is enabled, false if it's not.
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. Unity's Material.GetTag Documentation
Parameters
tag
The name of the shader tag to retrieve.
searchFallbacks
Whether to look in the shader's fallbacks if the tag isn't found.
Returns
The value of the shader tag if it exists; otherwise, the defaultValue.
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. Unity's Material.GetTag Documentation
Parameters
tag
The name of the shader tag to retrieve.
searchFallbacks
Whether to look in the shader's fallbacks if the tag isn't found.
defaultValue
The value to return if the specified tag isn't found.
Returns
The value of the shader tag if it exists; otherwise, the defaultValue.
'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. Unity's Material.GetTexture Documentation
Parameters
nameID
Returns
The Texture object currently in use by the material.
'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. Unity's Material.GetTexture Documentation
Parameters
name
The name of the property to retrieve the texture from.
Returns
The Texture object currently in use by the material.
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. Unity's Material.GetTextureOffset Documentation
Parameters
nameID
Returns
The current texture offset of the material's property.
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. Unity's Material.GetTextureOffset Documentation
Parameters
name
The name of the property to get the texture offset from.
Returns
The current texture offset of the material's property.
Returns
Returns
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. Unity's Material.GetTextureScale Documentation
Parameters
nameID
Returns
The current texture tiling 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. Unity's Material.GetTextureScale Documentation
Parameters
name
The name of the property to get the texture scale from.
Returns
The current texture tiling of the material's 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. Unity's Material.GetVector Documentation
Parameters
nameID
Returns
The Vector4 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. Unity's Material.GetVector Documentation
Parameters
name
The property name to retrieve the Vector4 value from.
Returns
The Vector4 value of the specified property.
Parameters
nameID
Returns
Parameters
name
Returns
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. Unity's Material.HasBuffer Documentation
Parameters
nameID
Returns
Returns true if the buffer 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. Unity's Material.HasBuffer Documentation
Parameters
name
The name of the buffer property to check.
Returns
Returns true if the buffer property exists; false otherwise.
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. Unity's Material.HasColor Documentation
Parameters
nameID
Returns
Returns true if the color property exists; false otherwise.
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. Unity's Material.HasColor Documentation
Parameters
name
The name of the color property to check.
Returns
Returns true if the color 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. Unity's Material.HasConstantBuffer Documentation
Parameters
nameID
Returns
Returns true if the constant 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. Unity's Material.HasConstantBuffer Documentation
Parameters
name
The name of the constant buffer property to check.
Returns
Returns true if the constant buffer property exists; false otherwise.
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. Unity's Material.HasFloat Documentation
Parameters
nameID
Returns
Returns true if the float 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. Unity's Material.HasFloat Documentation
Parameters
name
The name of the float property to check.
Returns
Returns true if the float 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. Unity's Material.HasInteger Documentation
Parameters
nameID
Returns
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. Unity's Material.HasInteger Documentation
Parameters
name
The name for the integer property to check.
Returns
Returns true if the integer 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. Unity's Material.HasMatrix Documentation
Parameters
nameID
Returns
Returns true if the matrix 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. Unity's Material.HasMatrix Documentation
Parameters
name
The name of the matrix property to check.
Returns
Returns true if the matrix property exists; otherwise, false.
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. Unity's Material.HasProperty Documentation
Parameters
nameID
The identifier for the property you are checking for.
Returns
Returns true if the property exists; otherwise, false.
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. Unity's Material.HasProperty Documentation
Parameters
name
Returns
Returns true if the 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. Unity's Material.HasTexture Documentation
Parameters
nameID
Returns
Returns true if the texture 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. Unity's Material.HasTexture Documentation
Parameters
name
The name of the texture property to check.
Returns
Returns true if the texture property exists; otherwise, false.
The 'HasVector' method checks if a specific vector property exists in the material. This can help in preventing errors when trying to access this property. Unity's Material.HasVector Documentation
Parameters
nameID
Returns
Returns true if the vector property exists; otherwise, false.
The 'HasVector' method checks if a specific vector property exists in the material. This can help in preventing errors when trying to access this property. Unity's Material.HasVector Documentation
Parameters
name
The name of the vector property to check.
Returns
Returns true if the vector property exists; otherwise, false.
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. Unity's Material.IsKeywordEnabled Documentation
Parameters
keyword
The keyword to check.
Returns
Returns true if the keyword is enabled, false otherwise.
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. Unity's Material.Lerp Documentation
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. Unity's Material.SetColor Documentation
Parameters
nameID
value
The color value to set the property to.
Returns
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. Unity's Material.SetColor Documentation
Parameters
name
The name for the color property to set.
value
The color value to set the property to.
Returns
Parameters
nameID
values
Returns
Parameters
name
values
Returns
'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. Unity's Material.SetFloat Documentation
Parameters
nameID
value
The float value to set the property to.
Returns
'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. Unity's Material.SetFloat Documentation
Parameters
name
The name of the property to set.
value
The float value to set the property to.
Returns
Parameters
nameID
values
Returns
Parameters
name
values
Returns
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. Unity's Material.SetInteger Documentation
Parameters
nameID
value
The integer value to set the property to.
Returns
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. Unity's Material.SetInteger Documentation
Parameters
name
The name of the property to set.
value
The integer value to set the property to.
Returns
'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. Unity's Material.SetMatrix Documentation
Parameters
nameID
value
The Matrix4x4 value to set the property to.
Returns
'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. Unity's Material.SetMatrix Documentation
Parameters
name
The name of the Matrix4x4 property to set.
value
The Matrix4x4 value to set the property to.
Returns
Parameters
nameID
values
Returns
Parameters
name
values
Returns
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. Unity's Material.SetOverrideTag Documentation
Parameters
tag
The tag to be overridden in this material.
val
The value to set for the overridden tag.
Returns
'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. Unity's Material.SetPass Documentation
Parameters
pass
The index of the pass to set.
Returns
If the shader or pass is not valid, this function will return false; otherwise, it returns true.
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. Unity's Material.SetShaderPassEnabled Documentation
Parameters
passName
The name of the Shader pass to enable or disable.
enabled
Whether the Shader pass should be enabled.
Returns
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. Unity's Material.SetTexture Documentation
Parameters
nameID
value
The Texture object to use.
Returns
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. Unity's Material.SetTexture Documentation
Parameters
name
The name of the texture property to set.
value
The Texture object to use.
Returns
The 'SetTextureOffset' method adjusts the texture coordinates of a material, effectively shifting the texture. This can be useful for creating effects like scrolling textures. Unity's Material.SetTextureOffset Documentation
Parameters
nameID
value
The amount of texture offset to apply.
Returns
The 'SetTextureOffset' method adjusts the texture coordinates of a material, effectively shifting the texture. This can be useful for creating effects like scrolling textures. Unity's Material.SetTextureOffset Documentation
Parameters
name
The property name to which Texture offset will be applied.
value
The amount of texture offset to apply.
Returns
'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. Unity's Material.SetTextureScale Documentation
Parameters
nameID
value
The amount of texture scaling to apply.
Returns
'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. Unity's Material.SetTextureScale Documentation
Parameters
name
The property name to which Texture scaling will be applied.
value
The amount of texture scaling to apply.
Returns
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. Unity's Material.SetVector Documentation
Parameters
nameID
value
The Vector4 value to set the property to.
Returns
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. Unity's Material.SetVector Documentation
Parameters
name
The name of the Vector4 property to set.
value
The Vector4 value to set the property to.
Returns
Parameters
nameID
values
Returns
Parameters
name
values
Returns
Updated 18 days ago