Get Unity Graphic Settings Current Variants List by Script.

Hi again unity masters,

Im trying to get the Current Tracked Shaders as;

Edit, Project Settings, Graphics.
Scroll Down and there is a String that says:
Currently Tracked : X shaders X total variants.

Is there a way to access that ShaderVariantCollection.ShaderVariant by script?
I want to make the process of creating shaders variant easier. For example:
Play the Game in editor →
Start Scene, call some code like;
ShaderUtil.ClearCurrentTrackedVariants();
Finish the Scene, call some code like;
ShaderUitl.GetCurrentlyTrackedVariantList();
SaveAsset(AutoGeneratedVariants + “SceneID_” + SceneID);

Im trying to create my own code for it but I’m getting problems detecting the variants, It always add ALL the possible variants and IsKeywordEnabled always return True;

String[] keyWorlds = mr.material.shaderKeywords;
                    List<String> variantKey = new List<string>();
                    for (int j = 0; j < keyWorlds.Length; j++)
                    {
                        if(mr.material.IsKeywordEnabled(keyWorlds[j]) == true)
                        {
                            variantKey.Add(keyWorlds[j]);
                        }
                          
                    }

So would be nice to use unity own function for that.

Regards
Fran.

1 Like

I have found those functions but looks like they are internal of unity and I can’t use it.

ShaderUtil.GetCurrentShaderVariantCollectionShaderCount();
ShaderUtil.GetCurrentShaderVariantCollectionVariantCount();
ShaderUtil.SaveCurrentShaderVariantCollection(assetPath);
ShaderUtil.ClearCurrentShaderVariantCollection();

2 Likes

OK.

Just did it.
using System.Reflection I called unity internal function.
Now I’m making shader variants automatically and later warm them up.

2 Likes