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. Dismiss Notice

Bug Keywords nested in subgraphs are not generated

Discussion in 'Shader Graph' started by alexanderameye, Jul 16, 2020.

  1. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    I have this graph where I have a subgraph connected to the output.



    The subgraph "Water UV" looks like this.



    So based on a keyword, the output is either set to world space UVs or mesh UVs.

    Then, using C# I control the keyword by its reference using material.EnableKeyword("").

    This works fine!

    The issue arises when I put the 'Water UV' subgraph into another subgraph. So for example like this.



    Here I have a subgraph called 'test', which simply outputs the Water UV subgraph.



    Now, changing the keyword using c# no longer has any effects.

    It seems that when I nest the subgraph (that holds the keyword) into another subgraph, the keywords are no longer generated.

    I checked this in the generated code.

    When I don't nest it I see

    #pragma shader_feature_local WATER_UV_WORLD WATER_UV_LOCAL

    as expected.

    When I nest it, I see

    // GraphKeywords: <None>

    Why are the keywords no longer generated when they are being nested?
     
    Last edited: Jul 16, 2020
  2. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    152
    I'm still seeing this problem in unity 2022.2.16, shader graph 14.0.7.

    A less than ideal workaround is to define the keywords in the top-level subgraph. The keywords don't need to be hooked up to anything in the top-level subgraph, just defined. Then the nested subgraphs can use the keywords like normal.
     
    alexanderameye likes this.