Version: 2022.3
LanguageEnglish
  • C#

Material

class in UnityEngine

/

Inherits from:Object

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

The material class.

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.

See Also: Materials, Shaders.

Properties

colorThe main color 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.
mainTextureOffsetThe offset of the main texture.
mainTextureScaleThe scale of the main texture.
parentParent of this material.
passCountHow many passes are in this material (Read Only).
renderQueueRender queue of this material.
shaderThe shader used by the material.
shaderKeywordsAn array containing names of the local shader keywords that are currently enabled for this material.

Constructors

Material

Public Methods

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 GetFloat or GetInteger instead.
GetIntegerGet a named integer value.
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 HasFloat or 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 a color value.
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 SetFloat or 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 named vector value.
SetVectorArraySets a vector array property.

Inherited Members

Properties

hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.

Public Methods

GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.

Static Methods

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
FindObjectsOfTypeGets a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961