Version: 2022.1
LanguageEnglish
  • C#

GlobalKeyword.Create

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

Declaration

public static Rendering.GlobalKeyword Create(string name);

Parameters

name The name of the global shader keyword.

Returns

GlobalKeyword Returns a new instance of the GlobalKeyword class.

Description

Creates and returns a GlobalKeyword that represents a new or existing global shader keyword.

Unity creates and returns a GlobalKeyword struct to represent the global shader keyword with the given name. If a global shader keyword with the given name does not yet exist in Unity's internal list of global shader keywords, Unity adds a global shader keyword with the given name to the list.

The following example creates a GlobalKeyword struct with the name EXAMPLE_FEATURE_ON, and caches it. It provides functions to enable and disable it.

using UnityEngine;
using UnityEngine.Rendering;

public class GlobalKeywordExample : MonoBehaviour { private GlobalKeyword exampleFeatureKeyword;

private void Start() { var exampleFeatureKeyword = GlobalKeyword.Create("EXAMPLE_FEATURE_ON"); }

public void EnableExampleFeature() { Shader.EnableKeyword(exampleFeatureKeyword); }

public void DisableExampleFeature() { Shader.DisableKeyword(exampleFeatureKeyword); } }