Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug NullReferenceException: Object reference not set to an instance of an object

Discussion in 'HDRP Ray Tracing' started by Rowlan, Oct 25, 2020.

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,294
    My console is flooded with these exceptions, the screen is black:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.AddInstanceToRAS (UnityEngine.Renderer currentRenderer, System.Boolean rayTracedShadow, System.Boolean aoEnabled, System.Int32 aoLayerValue, System.Boolean reflEnabled, System.Int32 reflLayerValue, System.Boolean giEnabled, System.Int32 giLayerValue, System.Boolean recursiveEnabled, System.Int32 rrLayerValue, System.Boolean pathTracingEnabled, System.Int32 ptLayerValue) (at Library/PackageCache/com.unity.render-pipelines.high-definition@10.1.0/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs:183)
    3. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.BuildRayTracingAccelerationStructure (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera) (at Library/PackageCache/com.unity.render-pipelines.high-definition@10.1.0/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs:494)
    4. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.ExecuteRenderRequest (UnityEngine.Rendering.HighDefinition.HDRenderPipeline+RenderRequest renderRequest, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.AOVRequestData aovRequest) (at Library/PackageCache/com.unity.render-pipelines.high-definition@10.1.0/Runtime/RenderPipeline/HDRenderPipeline.cs:2375)
    5. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Camera[] cameras) (at Library/PackageCache/com.unity.render-pipelines.high-definition@10.1.0/Runtime/RenderPipeline/HDRenderPipeline.cs:2269)
    6. UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera[] cameras) (at <0e343a50133148b6b99f9915103a7af3>:0)
    7. UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, System.Collections.Generic.List`1[T] renderRequests, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <0e343a50133148b6b99f9915103a7af3>:0)
    8. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    9.  
    The relevant part of the code (last line):

    Code (CSharp):
    1.         AccelerationStructureStatus AddInstanceToRAS(Renderer currentRenderer,
    2.             bool rayTracedShadow,
    3.             bool aoEnabled, int aoLayerValue,
    4.             bool reflEnabled, int reflLayerValue,
    5.             bool giEnabled, int giLayerValue,
    6.             bool recursiveEnabled, int rrLayerValue,
    7.             bool pathTracingEnabled, int ptLayerValue)
    8.         {
    9.             // Get all the materials of the mesh renderer
    10.             currentRenderer.GetSharedMaterials(materialArray);
    Unity 2020.2.0b8, HDRP 10.1.0

    Any idea what might be causing this and how to solve it? I already deleted the Library folder, rebuilt all, etc.

    I reduced the problem to LODed gameobjects. Can file a bug report with it if requested.

    The standard scene works without problems.
     
    Last edited: Oct 25, 2020
    hfkumot and Maltech-9 like this.
  2. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,294
    I figured that clicking on LOD kinda creates a renderer which solves the problem. But I have like 1000 of those. How can I fix that automatically? It's like in HDRP where the inspector fixes everything:

    lod-renderer.gif
     
    hfkumot likes this.
  3. Pranav_Redstoneinvente

    Pranav_Redstoneinvente

    Joined:
    Apr 13, 2018
    Posts:
    121
  4. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,294
    No. I had that same problem in the latest alpha.
     
  5. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Hum. It looks like this old bug that has been fixed and backported to latest HDRP 10.7.0. (Fix wouldn't be in 10.1.0 though). Does all your LOD have a renderer ?

    However, I'm really surprised that this still happen in latest alpha, maybe we missed something, do you have a repro ?

    In addition, ray tracing supports LOD now. (HDRP 13)
     
  6. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,294
    No, that's the problem, not all LODs have a renderer. Hitting play works in HDRP, but totally fails when anything raytracing related is active. It's as simple as having a LOD group without a renderer and activating raytrcing in the ambient occlusion setting. Or anything else for that matter.

    And all you get is this: "NullReferenceException: Object reference not set to an instance of an object" floodfilling the console and a black screen.

    It would at least save time if the console would show which gameobject causes the problem. With hundreds of gameobjects that get imported when you buy an asset from the store it's quite a waste of time to figure out why this doesn't work.

    This has already cost me so much time to figure out the culprit in various assets, I'm happy to create a repro case so that this gets finally fixed once and for all :)

    This happens in 2022.1.0.a11 with HDRP 13.
     
  7. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,294
    @chap-unity I uploaded a minimal verifiable repro project, Case 1372965
     
  8. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Thanks I will have a look :)
     
    Rowlan likes this.
  9. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,294
    Have you been able to reproduce this? It's really annoying. eg the Unity Auto Showroom looks like this:

    showroom.png
    Because some Beams don't have Renderers.
    rend.png

    It's supposed to look like this which happens once you disable the beams:

    car.png
     
  10. m0nsky

    m0nsky

    Joined:
    Dec 9, 2015
    Posts:
    257
    A fix was made for this issue initially (PR #6016), but not merged. This is because the next version of HDRP will significantly change the CPU side of ray tracing under the hood. This means your issue should no longer appear and you should see a massive performance increase on the CPU side for ray tracing. (can even get up to 30x CPU performance, depending on the scene size), check out the details in PR #5988.

    It has been merged into master 8 days ago, so it should land in the next 2022.x release.

    I'm not sure if these changes (CullInstances API on the editor side) will land in 2021.x, in that case 2021.x will still need a fix for the issue so it would probably be a good idea to backport the other fix (PR #6016) to 2021.x, @chap-unity probably knows more about this.
     
    Last edited: Oct 23, 2021
    Rowlan likes this.
  11. Pranav_Redstoneinvente

    Pranav_Redstoneinvente

    Joined:
    Apr 13, 2018
    Posts:
    121
    If you want to replicate it, simply add the Adams Project and use HDRP with it
     
  12. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Yes @m0nsky is right, the fix conflicted with a refactor on one improvement on how the RTAS was build so it was closed.
    However, the refactor also fixed the issue so now it shouldn't appear anymore.

    I'll have a look at previous versions (since we won't backport the refactor) to see where we should still fix this issue.
    In the meantime if you can't update, you can just add this one line to fix it for you.

    Edit: Still repro in 2021.2 but not in previous versions since LOD are not supported in raytracing before, we'll fix it there.
     
    Last edited: Oct 25, 2021
    m0nsky and Rowlan like this.
  13. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    94
    So DXR is basically unusable until moving to 2022?

    I did that fix above but still getting this spammed in console in play mode:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.AddInstanceToRAS (UnityEngine.Renderer currentRenderer, System.Boolean rayTracedShadow, System.Boolean aoEnabled, System.Int32 aoLayerValue, System.Boolean reflEnabled, System.Int32 reflLayerValue, System.Boolean giEnabled, System.Int32 giLayerValue, System.Boolean recursiveEnabled, System.Int32 rrLayerValue, System.Boolean pathTracingEnabled, System.Int32 ptLayerValue) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.0/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs:161)
    3. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.BuildRayTracingAccelerationStructure (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.0/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs:511)
    4. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.ExecuteRenderRequest (UnityEngine.Rendering.HighDefinition.HDRenderPipeline+RenderRequest renderRequest, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.AOVRequestData aovRequest) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.0/Runtime/RenderPipeline/HDRenderPipeline.cs:1945)
    5. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.high-definition@12.1.0/Runtime/RenderPipeline/HDRenderPipeline.cs:1836)
    6. UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <de62ab64366d4d29973fce8773660238>:0)
    7. UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, System.Collections.Generic.List`1[T] renderRequests, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <de62ab64366d4d29973fce8773660238>:0)
    8. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    Edit: seems reapplying the fix got it to stick this time but DXR only working in Scene view for some reason.
     
    Last edited: Oct 28, 2021
  14. m0nsky

    m0nsky

    Joined:
    Dec 9, 2015
    Posts:
    257
    No, this was only an issue for incorrectly set up LOD groups (if there was a missing renderer), and the fix will also be backported to 2021.2.

    The best solution would probably be to set up the LOD group correctly, or wait for the next official release that includes the fix. You can also apply the fix manually, but it requires some basic knowledge of unity packages.

    However, if you make heavy use of DXR, I can recommend trying out 2022.1 because it comes with some great performance gains regarding DX12/DXR.
     
  15. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    94
    Is the editor also more stable? I've noticed when converting my large world game to ray tracing in 2021.2 the editor is crashing a lot.
     
  16. m0nsky

    m0nsky

    Joined:
    Dec 9, 2015
    Posts:
    257
    The only possible crash I know of is when working with millions of polygons in the acceleration structure, and framerates get as low as 1-2 fps, it could even be a VRAM issue at that point, I am not sure.

    It's bad practice and you shouldn't come across this scenario in production, but I agree it shouldn't crash, not even in development. I will have a look if I can reproduce this in a test project and report it.
     
  17. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    94
    Appears the fix didn't make it into the 2022.1.0a13.1822 release, guess I'll have to wait another 1-2 weeks for next release :(
     
  18. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Indeed, the a13 contains fixes merged before Nov 4th, and the RTAS refactor got merged on Nov 14th.
    Next batch should be available in 2 weeks tops
     
  19. TheGamery

    TheGamery

    Joined:
    Oct 14, 2013
    Posts:
    94
    I just tested again with a15 and still getting it:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.AddInstanceToRAS (UnityEngine.Renderer currentRenderer, System.Boolean rayTracedShadow, System.Boolean aoEnabled, System.Int32 aoLayerValue, System.Boolean reflEnabled, System.Int32 reflLayerValue, System.Boolean giEnabled, System.Int32 giLayerValue, System.Boolean recursiveEnabled, System.Int32 rrLayerValue, System.Boolean pathTracingEnabled, System.Int32 ptLayerValue) (at Library/PackageCache/com.unity.render-pipelines.high-definition@13.1.0/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs:161)
    3. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.BuildRayTracingAccelerationStructure (UnityEngine.Rendering.HighDefinition.HDCamera hdCamera) (at Library/PackageCache/com.unity.render-pipelines.high-definition@13.1.0/Runtime/RenderPipeline/Raytracing/HDRaytracingManager.cs:511)
    4. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.ExecuteRenderRequest (UnityEngine.Rendering.HighDefinition.HDRenderPipeline+RenderRequest renderRequest, UnityEngine.Rendering.ScriptableRenderContext renderContext, UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.HighDefinition.AOVRequestData aovRequest) (at Library/PackageCache/com.unity.render-pipelines.high-definition@13.1.0/Runtime/RenderPipeline/HDRenderPipeline.cs:1945)
    5. UnityEngine.Rendering.HighDefinition.HDRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at Library/PackageCache/com.unity.render-pipelines.high-definition@13.1.0/Runtime/RenderPipeline/HDRenderPipeline.cs:1836)
    6. UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <2325cc54de6040309d03768ffdba64e6>:0)
    7. UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, System.Collections.Generic.List`1[T] renderRequests, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <2325cc54de6040309d03768ffdba64e6>:0)
    8. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    9.  
     
  20. m0nsky

    m0nsky

    Joined:
    Dec 9, 2015
    Posts:
    257
    There was no new HDRP release for a15 (I assume a15 uses the a13 package), but the package for a16 is already up, so the fix will be included in a16. (more info here)
     
    chap-unity likes this.
  21. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    I'm getting this in 2021.3.5f1 almost a year later and no fix. UNITY CEO needs to start aiming for stability than cloud builds and cloud compiles and cloud assets and other things almost no one uses.
     
  22. Delta_jom

    Delta_jom

    Joined:
    Jan 12, 2021
    Posts:
    1
    maybesolved.png Not sure if exactly the same issue, but for me, it seemed to resolve if you go into project settings > Quality > HDRP, and for each HDRP asset set the Maximum LOD level to a number greater than zero for Low, Medium and High.

    My project is small so doesn't make a big difference for me. (Unity 2021.3.4f1, HDRP version 12.1.7)
     
  23. Stanislav-Botev

    Stanislav-Botev

    Joined:
    Apr 13, 2013
    Posts:
    24
    Same bug happens in 2022.5 --> this solution works!
     
    Juniorjarvis likes this.
  24. Juniorjarvis

    Juniorjarvis

    Joined:
    May 6, 2018
    Posts:
    1
    Had this issue using Unity 2022.2.17 same as Stanislav had the same issue, and Delta_jom is a savior this fixed it amazing thank you!
     
  25. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
    Works in 2022.2.8f1.

    Broken piece of trash engine.
     
  26. goodnewsjimdotcom

    goodnewsjimdotcom

    Joined:
    May 24, 2017
    Posts:
    342
    Dog and Pony EA ceo overpromising glitz and glam, none of the substance of real love that an engine should get.

    UNITY is OP, but getting sketchier in the long run instead of more stable.
     
  27. FruityFreddy

    FruityFreddy

    Joined:
    Nov 8, 2023
    Posts:
    1
    I am using Unity 2022.3.13 and I can't seem to find individual HDRP values, only 1 and changing that doesn't work... Can anybody help me, I ave n clue what to do. upload_2023-11-28_13-57-57.png