SetKeyword and EnableKeyword do not appear to function properly with the Universal Render Pipeline/ComplexLit shader in Unity 2021.3.2f1. I have a Material within the Project, and I am in the Editor (so the game is not playing - I’m in Editor Mode). My code looks like this:
string inKeyword = "_CLEARCOATMAP";
LocalKeyword keyword = new LocalKeyword(materialReference.shader, inKeyword);
materialReference.EnableKeyword(keyword);
Debug.Log("--- Keyword " + inKeyword + " on material instance " + materialReference.GetInstanceID() + " is now " + materialReference.IsKeywordEnabled(inKeyword));
(Please note that the following result occurs regardless of if we use EnableKeyword or SetKeyword. The result is identical in both cases).
The debug output for this operation is:
— Keyword _CLEARCOATMAP on material instance -13860 is now True
However, when viewing the Material, the operation has actually either failed to complete, or the result was reverted, as the Debug side looks like this (note the Instance ID is indeed the same, so we’re on the correct Material instance):
And the Material Inspector itself displays this:
Could someone please advise on what I am doing wrong, or if I need to make this a formal bug report with Unity?
Thank you!