Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

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

Submission failed

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

Close

Cancel

Switch to Manual

Parameters

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.

Returns

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

Description

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."); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961