2022.2 Deriving from "UniversalRenderPipelineAsset" errors with NullReferenceException

Hi,

in Unity 2021.3, it was possible to simply create a custom RenderPipelineAsset by deriving from UniversalRenderPipelineAsset

[CreateAssetMenu(menuName = "Rendering/My URP Asset (Pipeline Asset)")]
public class MyURPAsset : UniversalRenderPipelineAsset {
     protected override RenderPipeline CreatePipeline() {
        RenderPipeline rp = base.CreatePipeline();
        DoSomeStuff();
        return rp;
    }
}

With Unity 2022.2.18, there are multiple parts, where Unity tries to reference texture files with a “Reload”-Attribute. Those are always null and result into the NullReferenceException once they are accessed.

ScreenSpaceAmbientOcclusionSettings

[Reload("Textures/BlueNoise256/LDR_LLL1_{0}.png", 0, 7)]
public Texture2D[] m_BlueNoise256Textures;

UniversalRenderPipelineAsset

[Serializable, ReloadGroup]
public sealed class TextureResources
{
    /// <summary>
    /// Pre-baked blue noise textures.
    /// </summary>
    [Reload("Textures/BlueNoise64/L/LDR_LLL1_0.png")]
    public Texture2D blueNoise64LTex;
    /// <summary>
    /// Bayer matrix texture.
    /// </summary>
    [Reload("Textures/BayerMatrix.png")]
    public Texture2D bayerMatrixTex;

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.Rendering.Universal.ScreenSpaceAmbientOcclusion.AddRenderPasses (UnityEngine.Rendering.Universal.ScriptableRenderer renderer, UnityEngine.Rendering.Universal.RenderingData& renderingData) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/RendererFeatures/ScreenSpaceAmbientOcclusion.cs:130)
UnityEngine.Rendering.Universal.ScriptableRenderer.AddRenderPasses (UnityEngine.Rendering.Universal.RenderingData& renderingData) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/ScriptableRenderer.cs:1362)
UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.CameraData& cameraData, System.Boolean anyPostProcessingEnabled) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:638)
UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderCameraStack (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera baseCamera) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:817)
UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List1[T] cameras) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.7/Runtime/UniversalRenderPipeline.cs:362) UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List1[T] cameras) (at :0)
UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at :0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Is there any chance to fix the issue or point the reload attribute to the correct path of the original pipeline asset?

1 Like

Experiencing the same issue slightly differently. In our project the active pipeline can be replaced via addressables. So the pipeline assets are made in Unity 2021.3.19f1 and they don’t have blueNoise64LTex or bayerMatrixTex at all which then makes camera rendering not functional on addressable load (we wrote a code that immediately reads pipeline asset from addressables). However, LOD cross fading seems to be enabled by default in pipeline assets which then makes the UniversalRenderPipeline attempt to set one of the noise textures, which seems to be blue noise by default. We are able to fix it by either removing support for custom pipelines or updating the addressable projects but this is really inconvenient. Ideally, there should be null check in SetupPerFrameShaderConstants() (see “function to improve.png”). The exact error was this in our case:

(Filename: ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.10/Runtime/UniversalRenderPipeline.cs Line: 1642)

NullReferenceException: Object reference not set to an instance of an object
at UnityEngine.Rendering.Universal.UniversalRenderPipeline.SetupPerFrameShaderConstants () [0x00085] in .\Library\PackageCache\com.unity.render-pipelines.universal@14.0.10\Runtime\UniversalRenderPipeline.cs:1642
at UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List1[T] cameras) [0x00070] in .\Library\PackageCache\com.unity.render-pipelines.universal@14.0.10\Runtime\UniversalRenderPipeline.cs:336 at UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List1[T] cameras) [0x0001c] in C:\build\output\unity\unity\Runtime\Export\RenderPipeline\RenderPipeline.cs:52
at UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest) [0x00041] in C:\build\output\unity\unity\Runtime\Export\RenderPipeline\RenderPipelineManager.cs:132

We really looking forward for the patch release until we move our projects to production with Unity 2022.3.20f1. It was also a lot more difficult to find out the issue because first it was found in WebGL and WebGL didn’t report the exact location of the null reference even in dev mode with full stack trace enabled. We had to build Windows build instead.