Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to use Shader.SetKeyword

Discussion in 'Shaders' started by h-nakagawa, Feb 22, 2023.

  1. h-nakagawa

    h-nakagawa

    Joined:
    Nov 24, 2021
    Posts:
    4
    When I turn on Global Shader keyword with Shader.SetKeyword, I get the error "Global keyword _GLOBAL_KWD doesn't exist".

    I have wrote pragma on the shader below
    #pragma multi_compile _ _GLOBAL_KWD

    And Shader.SetKeyword(new GlobalKeyword("_GLOBAL_KWD"), true); on the script.

    I have tried with both URP/Builtin RenderPipelines and get the same error.
    Is there mistakes somewhere?

    The procedure to reproduce the error in the attached project is as follows
    1) Open SampleScene.
    2) Play.
    3) Press the top left button.
    4) Console says "Global keyword _GLOBAL_KWD doesn't exist".

    Thank you in advance.
     

    Attached Files:

  2. h-nakagawa

    h-nakagawa

    Joined:
    Nov 24, 2021
    Posts:
    4
    I've missed to write a version it is 2021.3.9f1.
     
  3. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Use
    GlobalKeyword.Create(string)
    or
    Shader.EnableKeyWord(string)
     
  4. h-nakagawa

    h-nakagawa

    Joined:
    Nov 24, 2021
    Posts:
    4
    Thank you very much!