Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. 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

HDRP build: Cannot create required material because shader is null

Discussion in 'Graphics Experimental Previews' started by dgoyette, May 15, 2019.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,196
    I've finished migrating my game from Unity 2018.3 to Unity 2019.1, with HDRP 5.13. The game builds, but when running it, it hangs on the splash screen. Looking at the log file, I see it's throwing errors related to being unable to instantiate some materials:

    Cannot create required material because shader is null
    UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:LogError(Object)
    UnityEngine.Rendering.CoreUtils:CreateEngineMaterial(Shader) (at C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.core@5.13.0\Runtime\Utilities\CoreUtils.cs:323)
    UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline:.ctor(HDRenderPipelineAsset) (at C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipeline.cs:314)
    UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipelineAsset:CreatePipeline() (at C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipelineAsset.cs:35)
    UnityEngine.Rendering.RenderPipelineAsset:InternalCreatePipeline() (at C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineAsset.cs:9)
    UnityEngine.Rendering.RenderPipelineManager:prepareRenderPipeline(RenderPipelineAsset) (at C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineManager.cs:84)
    UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal(RenderPipelineAsset, Camera[], IntPtr) (at C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineManager.cs:57)

    (Filename: C:/Users/Dan/Documents/GitHub/Gravia/Library/PackageCache/com.unity.render-pipelines.core@5.13.0/Runtime/Utilities/CoreUtils.cs Line: 323)

    Cannot create required material because shader is null
    UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    UnityEngine.Logger:Log(LogType, Object)
    UnityEngine.Debug:LogError(Object)
    UnityEngine.Rendering.CoreUtils:CreateEngineMaterial(Shader) (at C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.core@5.13.0\Runtime\Utilities\CoreUtils.cs:323)
    UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline:.ctor(HDRenderPipelineAsset) (at C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipeline.cs:315)
    UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipelineAsset:CreatePipeline() (at C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipelineAsset.cs:35)
    UnityEngine.Rendering.RenderPipelineAsset:InternalCreatePipeline() (at C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineAsset.cs:9)
    UnityEngine.Rendering.RenderPipelineManager:prepareRenderPipeline(RenderPipelineAsset) (at C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineManager.cs:84)
    UnityEngine.Rendering.RenderPipelineManager:DoRenderLoop_Internal(RenderPipelineAsset, Camera[], IntPtr) (at C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineManager.cs:57)

    (Filename: C:/Users/Dan/Documents/GitHub/Gravia/Library/PackageCache/com.unity.render-pipelines.core@5.13.0/Runtime/Utilities/CoreUtils.cs Line: 323)

    NullReferenceException: Object reference not set to an instance of an object
    at UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.DownsampleDepthForLowResTransparency (UnityEngine.Experimental.Rendering.HDPipeline.HDCamera hdCamera, UnityEngine.Rendering.CommandBuffer cmd) [0x00097] in C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipeline.cs:3230
    at UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.ExecuteRenderRequest (UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline+RenderRequest renderRequest, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd) [0x00f18] in C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipeline.cs:1924
    at UnityEngine.Experimental.Rendering.HDPipeline.HDRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Camera[] cameras) [0x00891] in C:\Users\Dan\Documents\GitHub\Gravia\Library\PackageCache\com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipeline\HDRenderPipeline.cs:1423
    at UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera[] cameras) [0x00020] in C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipeline.cs:72
    at UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, UnityEngine.Camera[] cameras, System.IntPtr loopPtr) [0x00025] in C:\buildslave\unity\build\Runtime\Export\RenderPipeline\RenderPipelineManager.cs:67

    (Filename: C:/Users/Dan/Documents/GitHub/Gravia/Library/PackageCache/com.unity.render-pipelines.high-definition@5.13.0-preview/Runtime/RenderPipeline/HDRenderPipeline.cs Line: 3230)

    I tried adding the shader it's complaining about (HDRP/DownsampleDepth) to the list of shaders to always include, but it doesn't change the behavior.

    This appears to cause the game to sit on the splash screen consuming 100% of one of the CPU cores, never getting past the splashscreen. Any ideas?
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,196
    I haven't been able to resolve this yet. Things I've tried:
    • Completely removing HDRP package and readding it.
    • Creating a new HDRP Asset, in case there was an issue with the one I migrated from 4.x.
    Depending on which scene I place first in my build, it either freezes on the splash screen, or it loads the scene but then spams the log file with a null reference exception at HDRenderPipeline.cs:3230.

    Trying to set up a clean HDRP project to see if it happens there.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,196
    I think I see what's going on here, and I have a workaround, but this seems really weird/messed up.

    Here's some diagnostics. It seems that HDRenderPipeline.cs create several materials via CoreUtils.CreateEngineMaterial. This was the case under 4.x, and with 5.x some additional materials were added. It seems that the crashes I'm experiencing are the result of some of those newer materials not instantiating due to the shader being null. I added some debug output, to print out the shaders and the value from the HDRP asset, and got this:
    • Name: copyStencilBufferPS; Shader: Hidden/HDRP/CopyStencilBuffer
    • Name: cameraMotionVectorsPS; Shader: Hidden/HDRP/CameraMotionVectors
    • Name: decalNormalBufferPS; Shader: Hidden/HDRP/Material/Decal/DecalNormalBuffer
    • Name: copyDepthBufferPS; Shader: Hidden/HDRP/CopyDepthBuffer
    • Name: downsampleDepthPS; Shader: null
    • Name: upsampleTransparentPS; Shader: null
    • Name: applyDistortionPS; Shader: Hidden/HDRP/ApplyDistortion
    • Name: debugViewMaterialGBufferPS; Shader: Hidden/HDRP/DebugViewMaterialGBuffer
    • Name: debugViewMaterialGBufferPS; Shader: Hidden/HDRP/DebugViewMaterialGBuffer
    • Name: debugDisplayLatlongPS; Shader: Hidden/HDRP/DebugDisplayLatlong
    • Name: debugFullScreenPS; Shader: Hidden/HDRP/DebugFullScreen
    • Name: debugColorPickerPS; Shader: Hidden/HDRP/DebugColorPicker
    • Name: blitPS; Shader: Hidden/HDRP/Blit
    You can see that downsampleDepthPS and upsampleTransparentPS are null. To be clear, this means that 'asset.renderPipelineResources.shaders.downsampleDepthPS' is null.

    If I look at "HDRenderPipelineResources.asset" under \com.unity.render-pipelines.high-definition@5.13.0-preview\Runtime\RenderPipelineResources, I find that the asset doesn't have any content for "downsampleDepthPS" or "upsampleTransparentPS". It has entries for all the other shaders listed above, but not the two that are giving me trouble. Weirdly, if I select this file in Unity, I see it, and it contains the shaders:

    upload_2019-5-15_23-35-57.png

    But if I show the same file in a text editor, those two entries are missing:

    upload_2019-5-15_23-37-57.png

    So it's a total mystery to me how this file is showing something in the Inspector that isn't in the file itself. If I look on GitHub, I see that the 5.13 version of HDRenderPipelineResources.asset also doesn't contain the shaders:

    https://github.com/Unity-Technologi...lineResources/HDRenderPipelineResources.asset

    It seems they were only added 13 days ago:

    https://github.com/Unity-Technologi...mmit/3e8c5df0d82a6ce158ab928f2f76f1ca79c96a65

    But those properties are referenced by a commit back in March:

    https://github.com/Unity-Technologi...mmit/2287b07b666c96d481260379ef2f2fcd63cc0b09

    So I'm totally confused about how this is all working.

    Anyway, my workaround was to create a copy of HDRenderPipelineResources.asset and add it to my Assets directory. Upon doing so, I can now see the two empty fields for downsampleDepthPS and upsampleTransparentPS, and I can assign the shaders to them. Now I can get passed those exceptions.

    So what could be happening here? Why, when I click on HDRenderPipelineResources.asset, does the inspector show me that the asset has values for downsampleDepthPS and upsampleTransparentPS, even though those values aren't in the file? Why does the 5.13 version of HDRP have a dependency on those values being in the HDRenderPipelineResources, when those values were only just added?
     
    manutoo likes this.
  4. manutoo

    manutoo

    Joined:
    Jul 13, 2010
    Posts:
    338
    @dgoyette ,
    I got the same issue, thanks to your explanations I managed to fix it in a similar way than yours without losing too much hair ! :)

    Mine has been even stranger : it happened once after I had changed the default fullscreen mode from fullscreen window to exclusive, so I rebuilt the game, and it worked fine for a couple rebuilds ; then I switched back the default fullscreen mode, and then there was no way to get ride of the error anymore by rebuilding the game..!
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,196
    This exact same issue occurred to me again, this time when updating my project from HDRP 7.3.1 to HDRP 7.4.1. This time, the HDRenderPipelineResources file appeared to show a reference to a shader for "Resolve Motion Vec PS":

    upload_2020-6-22_18-56-0.png

    However, if I make a copy of the HDRenderPipelineResources and drag it into my project, the editable version of this asset shows that the shader is null:

    upload_2020-6-22_18-56-55.png

    So, the Inspector is making it seem like this shader has a value assigned, but in reality it's null, and it results in an error being thrown by CoreUtils.CreateEngineMaterial().

    If I look on the GitHub project for HDRenderPipelineResources.asset under tag 7.4.1, the file is missing an entry for "resolveMotionVecPS":

    https://github.com/Unity-Technologi...lineResources/HDRenderPipelineResources.asset

    And yet, HDRP is trying to make use of it in the HDRenderPipeline.cs constructor:

    Code (CSharp):
    1. m_MotionVectorResolve = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.shaders.resolveMotionVecPS);
     
unityunity