Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Material

The material class.
Read time 8 minutesLast updated 4 days ago

Definition

  • Type: Class
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
  • Inherits from: Object
public class Material : Object

Remarks

This class exposes all properties from a material, allowing you to animate them. You can also use it to set custom shader properties that can't be accessed through the inspector (e.g. matrices).
In order to get the material used by an object, use the Renderer.material property.
Additional Resources: Materials, Shaders.

Constructors

Constructor

Description

Material(UnityEngine.Material)Create a temporary Material.
Material(UnityEngine.Shader)Create a temporary Material.

Properties

Property

Description

colorThe main color property of the Material.
doubleSidedGIGets and sets whether the Double Sided Global Illumination setting is enabled for this material.
enabledKeywordsAn array containing the local shader keywords that are currently enabled for this material.
enableInstancingGets and sets whether GPU instancing is enabled for this material.
globalIlluminationFlagsDefines how the material should interact with lightmaps and lightprobes.
isVariantReturns true if this material is a material variant.
mainTextureThe main texture.
mainTextureOffsetDefines the UV offset for the main texture in the Material. This property adjusts the position of the texture mapping on a Mesh surface relative to its UV coordinates.
mainTextureScaleThe scale of the main texture.
parentParent of this material.
passCountHow many passes are in this material (Read Only).
rawRenderQueueRaw render queue of this material.
renderQueueThe render queue to use as an override on this material.
shaderThe shader used by the material.
shaderKeywordsAn array containing names of the local shader keywords that are currently enabled for this material.

Methods

Method

Description

ApplyPropertyOverrideApplies an override associated with a Material Variant to a target.
ComputeCRCComputes a CRC hash value from the content of the material.
CopyMatchingPropertiesFromMaterialCopies properties, keyword states and settings from
mat
to this material, but only if they exist in both materials.
CopyPropertiesFromMaterialCopy properties from other material into this material.
DisableKeywordDisables a local shader keyword for this material.
EnableKeywordEnables a local shader keyword for this material.
FindPassReturns the index of the pass
passName
.
GetBufferGet a named Graphics Buffer value.
GetColorGet a named color value.
GetColorArrayGet a named color array.
GetConstantBufferGet a named Constant Buffer value.
GetFloatGet a named float value.
GetFloatArrayGet a named float array.
GetIntThis method is deprecated. Use Material.GetFloat or Material.GetInteger instead.
GetIntegerGet a named integer value. If the integer property is not found an exception is thrown.
GetMatrixGet a named matrix value from the shader.
GetMatrixArrayGet a named matrix array.
GetPassNameReturns the name of the shader pass at index
pass
.
GetPropertyNamesRetrieves a list of the named properties in the material that match the input property type.
GetShaderPassEnabledChecks whether a given Shader pass is enabled on this Material.
GetTagGet the value of material's shader tag.
GetTextureGet a named texture.
GetTextureOffsetGets the placement offset of texture
propertyName
.
GetTexturePropertyNameIDsReturn the name IDs of all texture properties exposed on this material.
GetTexturePropertyNamesReturns the names of all texture properties exposed on this material.
GetTextureScaleGets the placement scale of texture
propertyName
.
GetVectorGet a named vector value.
GetVectorArrayGet a named vector array.
HasBufferChecks if the ShaderLab file assigned to the Material has a ComputeBuffer property with the given name.
HasColorChecks if the ShaderLab file assigned to the Material has a Color property with the given name.
HasConstantBufferChecks if the ShaderLab file assigned to the Material has a ConstantBuffer property with the given name.
HasFloatChecks if the ShaderLab file assigned to the Material has a Float property with the given name. This also works with the Float Array property.
HasIntThis method is deprecated. Use Material.HasFloat or Material.HasInteger instead.
HasIntegerChecks if the ShaderLab file assigned to the Material has an Integer property with the given name.
HasMatrixChecks if the ShaderLab file assigned to the Material has a Matrix property with the given name. This also works with the Matrix Array property.
HasPropertyChecks if the ShaderLab file assigned to the Material has a property with the given name.
HasTextureChecks if the ShaderLab file assigned to the Material has a Texture property with the given name.
HasVectorChecks if the ShaderLab file assigned to the Material has a Vector property with the given name. This also works with the Vector Array property.
IsChildOfReturns True if the given material is an ancestor of this Material.
IsKeywordEnabledChecks whether a local shader keyword is enabled for this material.
IsPropertyLockedChecks whether a property is locked by this material.
IsPropertyLockedByAncestorChecks whether a property is locked by any of ancestor of this material.
IsPropertyOverridenChecks whether a property is overriden by this material.
LerpInterpolate properties between two materials.
RevertAllPropertyOverridesRemoves all property overrides on this material.
RevertPropertyOverrideRemoves the override on a property.
SetBufferSets a named buffer value.
SetColorSets the value of a color- or vector-type property.
SetColorArraySets a color array property.
SetConstantBufferSets a ComputeBuffer or GraphicsBuffer as a named constant buffer for the material.
SetFloatSets a named float value.
SetFloatArraySets a float array property.
SetIntThis method is deprecated. Use Material.SetFloat or Material.SetInteger instead.
SetIntegerSets a named integer value.
SetKeywordSets the state of a local shader keyword for this material.
SetMatrixSets a named matrix for the shader.
SetMatrixArraySets a matrix array property.
SetOverrideTagSets an override tag/value on the material.
SetPassActivate the given
pass
for rendering.
SetPropertyLockSets the lock state of a property for this material.
SetShaderPassEnabledEnables or disables a Shader pass on a per-Material level.
SetTextureSets a named texture.
SetTextureOffsetSets the placement offset of a given texture. The
name
parameter is defined in the shader. This method creates a new Material instance.
SetTextureScaleSets the placement scale of texture
propertyName
.
SetVectorSets a value for a named vector in the material.
SetVectorArraySets a vector array property.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.