Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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,539
    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,539
    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:
    761
    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:
    761
    By the way, this line (URP Lit) is the fall back shader.
    FallBackShader.jpg
     
  8. BOXOPHOBIC

    BOXOPHOBIC

    Joined:
    Jul 17, 2015
    Posts:
    506
    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?
     
  10. Killercreeper_55

    Killercreeper_55

    Joined:
    Nov 17, 2019
    Posts:
    1
    I solved delete extra included shaders here (Project settings - Graphics), and keep like that:
    upload_2024-2-20_21-30-53.png