Scripting API

Material

class in UnityEngine · UnityEngine.CoreModule · inherits from Object

38 of 82 of Unity's membersUnity's documentation
In Tassix

Surface appearance: a shader plus property values. Rendering uses the main color, main texture with its tiling and offset, the alpha cutoff and the render queue; other properties are stored and returned. HasProperty answers per shader, but values are shared between a property's names: URP's _BaseColor/_BaseMap and glTF's baseColorFactor/baseColorTexture/alphaCutoff are the built-in _Color/_MainTex/_Cutoff.

Constructors 1

Properties 11

Color color { get; set; }

The main color (_Color, also _BaseColor in URP).

bool doubleSidedGI { get; set; }
bool enableInstancing { get; set; }
MaterialGlobalIlluminationFlags globalIlluminationFlags { get; set; }

How the material's emission takes part in global illumination (none is baked here).

Texture? mainTexture { get; set; }
Vector2 mainTextureOffset { get; set; }
Vector2 mainTextureScale { get; set; }
int passCount { get; }
int renderQueue { get; set; }

The render queue; -1 (set) means the shader's.

Shader shader { get; set; }
string[] shaderKeywords { get; set; }

Methods 30

void CopyPropertiesFromMaterial(Material mat)
void DisableKeyword(string keyword)
void EnableKeyword(string keyword)
Color GetColor(string name)
Color GetColor(int nameID)
float GetFloat(int nameID)
float GetFloat(string name)
float[]? GetFloatArray(string name)
float[]? GetFloatArray(int nameID)
int GetInt(int nameID)
int GetInt(string name)
int GetInteger(string name)
Matrix4x4 GetMatrix(string name)
Matrix4x4 GetMatrix(int nameID)

A matrix set on the material; unset ones are the identity.

string GetTag(string tag, bool searchFallbacks, string defaultValue)
string GetTag(string tag, bool searchFallbacks)

A tag's value: the material's override, else the shader's, else the default.

Texture? GetTexture(int nameID)
Texture? GetTexture(string name)
Vector2 GetTextureOffset(int nameID)
Vector2 GetTextureOffset(string name)
Vector2 GetTextureScale(int nameID)
Vector2 GetTextureScale(string name)
Vector4 GetVector(int nameID)
Vector4 GetVector(string name)
Vector4[]? GetVectorArray(string name)
Vector4[]? GetVectorArray(int nameID)
bool HasProperty(string name)
bool HasProperty(int nameID)
bool IsKeywordEnabled(string keyword)
void SetColor(string name, Color value)
void SetColor(int nameID, Color value)
void SetFloat(int nameID, float value)
void SetFloat(string name, float value)
void SetFloatArray(string name, float[] values)
void SetFloatArray(string name, List<float> values)
void SetFloatArray(int nameID, float[] values)
void SetFloatArray(int nameID, List<float> values)

Array properties: kept on the material (project shaders don't read arrays yet).

void SetInt(int nameID, int value)
void SetInt(string name, int value)
void SetInteger(string name, int value)
void SetMatrix(string name, Matrix4x4 value)
void SetMatrix(int nameID, Matrix4x4 value)
void SetOverrideTag(string tag, string val)

Overrides a tag of the shader's (RenderType...) for this material.

bool SetPass(int pass)

Makes this material the one immediate drawing (GL) uses; true, as for any pass of a supported shader.

void SetTexture(int nameID, Texture? value)
void SetTexture(string name, Texture? value)
void SetTextureOffset(int nameID, Vector2 value)
void SetTextureOffset(string name, Vector2 value)
void SetTextureScale(string name, Vector2 value)
void SetTextureScale(int nameID, Vector2 value)
void SetVector(int nameID, Vector4 value)
void SetVector(string name, Vector4 value)
void SetVectorArray(string name, Vector4[] values)
void SetVectorArray(string name, List<Vector4> values)
void SetVectorArray(int nameID, Vector4[] values)
void SetVectorArray(int nameID, List<Vector4> values)

Not in Tassix yet 44

ApplyPropertyOverride ComputeCRC CopyMatchingPropertiesFromMaterial FindPass GetBuffer GetColorArray GetConstantBuffer GetFloatArray GetMatrixArray GetPassName GetPropertyNames GetShaderPassEnabled GetTexturePropertyNameIDs GetTexturePropertyNames GetVectorArray HasBuffer HasColor HasConstantBuffer HasFloat HasInt HasInteger HasMatrix HasTexture HasVector IsChildOf IsPropertyLocked IsPropertyLockedByAncestor IsPropertyOverriden Lerp RevertAllPropertyOverrides RevertPropertyOverride SetBuffer SetColorArray SetConstantBuffer SetFloatArray SetKeyword SetMatrixArray SetPropertyLock SetShaderPassEnabled SetVectorArray enabledKeywords isVariant parent rawRenderQueue