Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Material.GetTag

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

Sumbission failed

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

Close

Cancel

public function GetTag(tag: string, searchFallbacks: bool, defaultValue: string = ""): string;
public string GetTag(string tag, bool searchFallbacks, string defaultValue = "");
public def GetTag(tag as string, searchFallbacks as bool, defaultValue as string = "") as string

Description

Get the value of material's shader tag.

If the material's shader does not define the tag, defaultValue is returned.

If searchFallbacks is true then this function will look for tag in all subshaders and all fallbacks. If seachFallbacks is false then only the currently used subshader will be queried for the tag.

Using GetTag without searching through fallbacks makes it possible to detect which subshader is currently being used: add a custom tag to each subshader with different value, and query the value at run time. For example, Unity Pro's water uses this function to detect when the shader falls back to non-reflective one, and turns off reflection camera in that case.

	// Attach this to a gameObject that has a renderer.

var materialTag = "RenderType"; function Start() { var result : String = renderer.material.GetTag(materialTag, true, "Nothing"); if (result == "Nothing") Debug.LogError(materialTag + " not found in " + renderer.material.shader.name); else Debug.Log("Tag found!, its value: " + result); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public string materialTag = "RenderType";
    void Start() {
        string result = renderer.material.GetTag(materialTag, true, "Nothing");
        if (result == "Nothing")
            Debug.LogError(materialTag + " not found in " + renderer.material.shader.name);
        else
            Debug.Log("Tag found!, its value: " + result);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public materialTag as string = 'RenderType'

	def Start() as void:
		result as string = renderer.material.GetTag(materialTag, true, 'Nothing')
		if result == 'Nothing':
			Debug.LogError(((materialTag + ' not found in ') + renderer.material.shader.name))
		else:
			Debug.Log(('Tag found!, its value: ' + result))