Keywords nested in subgraphs are not generated

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:

Why are the keywords no longer generated when they are being nested?

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.

2 Likes