GetTag
Get the value of material's shader tag.
Read time 2 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
GetTag(string, bool, string)
Get the value of material's shader tag.
public string GetTag(string tag, bool searchFallbacks, string defaultValue)
Parameters
Returns
Type | Description |
|---|---|
| string |
Remarks
If the material's shader does not define the tag, is returned.
defaultValueIf is then this function will look for tag in all subshaders and all fallbacks. If is then only the currently used subshader will be queried for the tag.
searchFallbackstruesearchFallbacksfalseUsing 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 water uses this function to detect when the shader falls back to non-reflective one, and turns off reflection camera in that case.
GetTagExamples
using UnityEngine;public class Example : MonoBehaviour{ // Attach this to a gameObject that has a renderer. string materialTag = "RenderType"; void Start() { Renderer rend = GetComponent<Renderer>(); string result = rend.material.GetTag(materialTag, true, "Nothing"); if (result == "Nothing") { Debug.LogError(materialTag + " not found in " + rend.material.shader.name); } else { Debug.Log("Tag found!, its value: " + result); } }}
GetTag(string, bool)
Get the value of material's shader tag.
public string GetTag(string tag, bool searchFallbacks)
Parameters
Returns
Type | Description |
|---|---|
| string |
Remarks
If the material's shader does not define the tag, is returned.
defaultValueIf is then this function will look for tag in all subshaders and all fallbacks. If is then only the currently used subshader will be queried for the tag.
searchFallbackstruesearchFallbacksfalseUsing 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 water uses this function to detect when the shader falls back to non-reflective one, and turns off reflection camera in that case.
GetTagExamples
using UnityEngine;public class Example : MonoBehaviour{ // Attach this to a gameObject that has a renderer. string materialTag = "RenderType"; void Start() { Renderer rend = GetComponent<Renderer>(); string result = rend.material.GetTag(materialTag, true, "Nothing"); if (result == "Nothing") { Debug.LogError(materialTag + " not found in " + rend.material.shader.name); } else { Debug.Log("Tag found!, its value: " + result); } }}