Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Any way to know if a shader variant has been stripped from exported build?

Discussion in 'Shaders' started by stephero, May 22, 2020.

  1. stephero


    Feb 8, 2016
    Hi guys,

    I would like to know, from an exported build, if a shader variant has been stripped during the export. I am specially interested about the instancing variant.
    I have a shader which support GPU Instancing. However the material of this shader is created at runtime, and I enable the instancing via the scripting API.
    Since there is no material asset with instancing enabled using this shader in the project, the export strips the instancing variant of my shader when the "Instancing Variants" property is set to the default "Strip Unused" value in the Graphics Settings:

    Is there any way to know is my instancing variant has been stripped from the exported build?

    When I enable the instancing from script, the bool stays properly at true, so I cannot check that:
    Code (CSharp):
    1. material.enableInstancing = true;
    I also tried to check if the keyword INSTANCING_ON was enabled (via Material.IsKeywordEnabled) since it appears in the frame debugger, but it's never possible to retrieve it from script (even when the instancing variant is properly exported).

    Thank you.
  2. aleksandrk


    Unity Technologies

    Jul 3, 2017
    The easiest way is, probably, to check this visually - make the color output different based on this keyword and see what color you get.
  3. stephero


    Feb 8, 2016
    Hi and thanks for the suggestion.
    I would have prefer a way to trigger a proper error message, but it's better than nothing :)
    It could be useful to prevent from setting the enableInstancing property at true on a material which doesn't have the instancing variant available (the getter of the property could always return false).
    Or being able to retrieve the INSTANCING_ON keyword from script would make sense too.
    Last edited: May 23, 2020