Why Material.shaderKeywords returns out of date values?

I tried these steps:

  1. Create a material with ShaderA;
  2. Enable or disable some keywords on then material;
  3. Then the shader of the material to ShaderB which provides some different keywords;
  4. When I was going to get the Material.shaderKeywords of the material the result contains keywords from the previous ShaderA.

How to avoid this? How to make Material.shaderKeywords returns the keywords only with current associated shader?

From the docs (Unity - Scripting API: Material.shaderKeywords)
Material.shaderKeywords are additional keywords set by material. It doesn’t really matter what the shader has :slight_smile:
I guess you have to manually disable all the keywords on the material when you change the shader.

I’d like to gather the using keywords among my materials for my custom shader stripper but the Material.shaderKeywords can’t give me the actually validate keywords combination for it associated shader.

I think the closest to what you need is this API: Unity - Scripting API: ShaderKeyword

OK, I’ll try.