Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


TryConvertPropertyIDToName(int, out string)

Returns whether the property ID is valid and outputs the corresponding property name if it exists.
Read time 1 minuteLast updated 13 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

TryConvertPropertyIDToName(int, string)

public static bool TryConvertPropertyIDToName(int propertyID, out string name)

Parameters

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.

Returns

Type

Description

boolTrue if the property ID is valid and the name was successfully retrieved, false otherwise.

Remarks

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.

Examples

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."); } }}