| Parameter | Description |
|---|---|
| propertyID | The ID of the shader property to get the name of. Use Shader.PropertyToID to get an ID. |
| name | The string into which the method writes the property name corresponding to the given ID, or an empty string if the ID is invalid. |
Boolean True if the property ID is valid and the name was successfully retrieved, false otherwise.
Returns whether the property ID is valid and outputs the corresponding property name if it exists.
This method allows you to get the original property name using the ID of a shader property. Use the name only for debugging and introspection, because passing strings is slower than passing property IDs.
Property IDs that were not created with Shader.PropertyToID are considered invalid.
Compared to Shader.PropertyIDToName, using this method avoids ambiguity with null or empty strings in the situation where the property ID is invalid.
Additional resources: Shader.PropertyIDToName, Shader.PropertyToID.
using UnityEngine;
public class TryConvertPropertyIDToNameExample : MonoBehaviour { private void Start() { int propertyID = Shader.PropertyToID("_MainTex"); // prints "_MainTex" if (Shader.TryConvertPropertyIDToName(propertyID, out string retrievedName1)) { Debug.Log(retrievedName1); } else { Debug.Log("Property ID does not exist."); }
// prints "Property ID does not exist." int invalidId = 999999; if (Shader.TryConvertPropertyIDToName(invalidId, out string retrievedName2)) { Debug.Log(retrievedName2); } else { Debug.Log("Property ID does not exist."); } } }