Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question The default error shader

Discussion in 'Shaders' started by akalytapa, Jan 11, 2023.

  1. akalytapa

    akalytapa

    Joined:
    Jun 8, 2021
    Posts:
    7
    Is there any way in Unity to know, that there is magenta error shader present in the scene via script? Like, can we really know through code, that material, rendered in scene is actually magenta pink and not one we wanted?
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,497
    Grab all the materials referenced in the scene, and check if any have a
    .shader.name
    of
    "Hidden/InternalErrorShader"
     
    Last edited: Jan 12, 2023
    akalytapa likes this.
  3. akalytapa

    akalytapa

    Joined:
    Jun 8, 2021
    Posts:
    7
    Nice. Thank you! Could not find this
     
  4. akalytapa

    akalytapa

    Joined:
    Jun 8, 2021
    Posts:
    7
    Hmm, when I did this:

    Code (CSharp):
    1. Renderer[] renderers = FindObjectsOfType<Renderer>();
    2.         foreach (var renderer in renderers)
    3.         {
    4.             if (renderer.material.shader.name == "Hidden/InternalErrorShader")
    It always returns an actual name of shader, assigned to renderer, but not the error one uniny actually renders
     
  5. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,497
    If they're pink because they're simply not compatible with the pipeline you're currently using, then I'm not sure what the solution would be in that case. The method I posted will just handle the case for missing or broken shaders, not simply incompatible ones.

    You can try the
    shader.isSupported
    value as well to catch some other cases. But it still won't help for shader that simply don't render in the current pipeline.
     
    Last edited: Jan 12, 2023
  6. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    637
    shader.isSupported
    : returns true if the shader itself or any fallbacks setup in the shader are supported.

    The documentation said that it will return true for an unsupported shader with any available fallback (shader).

    I think you can also use the GPU's shader model level to check whether a shader is unsupported (magenta or ignored by the rendering)

    For example, if a geometry shader with no fallback shaders is running on a GPU with shader model 3.0, it (the mesh) will be ignored (completely transparent) because the GPU doesn't support it.
     
  7. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    637
    By the way, this line (URP Lit) is the fall back shader.
    FallBackShader.jpg
     
  8. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    481
    You can also check URP/HDRP shaders by checking the material render pipeline tag:


    Code (CSharp):
    1.                     if (material.GetTag("RenderPipeline", false) == "")
    2.                     {
    3.                         // BIRP shader
    4.                     }
    5.  
    6.                     if (material.GetTag("RenderPipeline", false) == "UniversalPipeline")
    7.                     {
    8.                         // URP shader
    9.                     }
    10.  
    11.                     if (material.GetTag("RenderPipeline", false) == "HDRenderPipeline")
    12.                     {
    13.                         // HDRP shader
    14.                     }
     
    Invertex likes this.
  9. akalytapa

    akalytapa

    Joined:
    Jun 8, 2021
    Posts:
    7
    Can you please describe, how it can help to find error shaders in scene?