Search Unity

Post Process Stack NullRefferenceException

Discussion in 'Editor & General Support' started by theonciest, Mar 20, 2019.

  1. theonciest

    theonciest

    Joined:
    Jan 22, 2017
    Posts:
    13
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Rendering.PostProcessing.AmbientOcclusion.IsEnabledAndSupported (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/Effects/AmbientOcclusion.cs:179)
    3. UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetLegacyCameraFlags (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:696)
    4. UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetupContext (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:781)
    5. UnityEngine.Rendering.PostProcessing.PostProcessLayer.BuildCommandBuffers () (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:468)
    6. UnityEngine.Rendering.PostProcessing.PostProcessLayer.OnPreCull () (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:402)
    7.  
    We keep getting this error pinging off over and over it goes between that and Suimono - Water System.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Suimono.Core.SuimonoModule.LateUpdate () (at Assets/SUIMONO - WATER SYSTEM 2/SCRIPTS/SuimonoModule.cs:704)
    3.  
    We keep trying to import Post Processing but sometimes it works, and sometimes it just doesn't show up in the viewport. We keep fixing stuff, and then this breaks, we fix this, then more things break, and then this breaks. But this error keeps occuring. Not just Suimono

    Thanks
     
  2. theonciest

    theonciest

    Joined:
    Jan 22, 2017
    Posts:
    13
    Also when it does work, it won't push through source tree to make it work. Always have to reinstall the package via window - package manager - post processing 2.1.3

    2.1.4 doesn't work for some reason.
     
  3. theonciest

    theonciest

    Joined:
    Jan 22, 2017
    Posts:
    13
  4. theonciest

    theonciest

    Joined:
    Jan 22, 2017
    Posts:
    13
  5. MisterZhou

    MisterZhou

    Joined:
    Nov 9, 2013
    Posts:
    15
    I have the same problem.
     
  6. theonciest

    theonciest

    Joined:
    Jan 22, 2017
    Posts:
    13
    conspiracy I tell you lol
     
  7. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    Bump. I just got the same issue
     
  8. PixelJ

    PixelJ

    Unity Technologies

    Joined:
    Nov 1, 2018
    Posts:
    216
    Same here.
     
  9. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    354
    Is this error immediately after importing the package, and then if entering play mode after importing the package?

    If it's the same bug that I was seeing then I submitted a bug report for this a while back that has now been reprod and is in the system (case 1171701).

    In my case it seemed to be that there is a hidden field in the PostProcessingLayer component on cameras, called "Resource" or something like that which is set when the object is imported or created. If the component shows as "missing script" because the package isn't installed, then installing the package doesn't correctly initialise that property and it spams errors to the console.

    The simplest way to resolve it is by restarting the editor after installing the post processing package. You can also try and ensure that any PostProcessingLayer components are disabled before the package is installed and then re-enabled after, though this might be a pain depending on your workflow. Hopefully it gets fixed soon.

    If this is a different error then apologies. Let me know and I'll remove this reply
     
    BruteHercules likes this.
  10. SteenPetersen

    SteenPetersen

    Joined:
    Mar 13, 2016
    Posts:
    104
  11. mokhabadi

    mokhabadi

    Joined:
    Jul 25, 2018
    Posts:
    28
    I finally found the solution:

    Code (CSharp):
    1.  
    2. using UnityEngine.Rendering.PostProcessing;
    3. public PostProcessResources postProcessResources;
    4. void Start()
    5. {
    6.         PostProcessLayer postProcessLayer = Camera.main.gameObject.AddComponent<PostProcessLayer>();
    7.         postProcessLayer.Init(postProcessResources);
    8.         postProcessLayer.volumeTrigger = Camera.main.transform;
    9.         postProcessLayer.volumeLayer = LayerMask.GetMask("YourLayer");
    10. }
    11.  
    then find "postProcessResources" in assets and set its reference.

    in short, you must "init" it yourself. it can't find postProcessResources.
     
    CharlieCafaro_HG, al33f and sama-van like this.
  12. sama-van

    sama-van

    Joined:
    Jun 2, 2009
    Posts:
    1,734
    Working a charm thanks!!
     
  13. ThomRobinGames

    ThomRobinGames

    Joined:
    May 20, 2020
    Posts:
    3
    In case you're like me and are not sure where Post-Process Resources is, it's in
    Packages->
    Post Processing->
    PostProcessing
     
    konsnos, al33f and maoyu815930 like this.
  14. Arshil111

    Arshil111

    Joined:
    Aug 19, 2017
    Posts:
    8
    I got the same problem. I removed the Post Processing Layer from my camera and re added it. It worked
     
  15. summernight2001519

    summernight2001519

    Joined:
    Jul 3, 2018
    Posts:
    2
    upload_2020-12-29_12-27-17.png
    This is my error message.
    And I found the problem.
    if you have a Post-process Debug enabled but the Post Process Layer is set to a disabled camera,
    It will cause a NullReferenceException
    upload_2020-12-29_12-29-5.png
    Hope this helps.
     
  16. brando_slc

    brando_slc

    Joined:
    Jan 4, 2017
    Posts:
    7
    This worked for me! I had the problem after merging two projects.
     
  17. lukicamukica

    lukicamukica

    Joined:
    Feb 11, 2016
    Posts:
    8
    How many bugs does this unity have...
    Thanks.
     
  18. eyupunity

    eyupunity

    Joined:
    Jul 25, 2019
    Posts:
    4
    Worked, thanks...
     
  19. tbelgrave

    tbelgrave

    Joined:
    Jul 29, 2006
    Posts:
    321
    Worked thank you! This is after starting a new project and merging a previous one.
     
  20. wechat_os_Qy059pDMl9ZjDxnyYerPKBK-U

    wechat_os_Qy059pDMl9ZjDxnyYerPKBK-U

    Joined:
    Sep 18, 2020
    Posts:
    1
    I got the same null reference problem. Then I found I got this problem because I first had the post process layer in camera, then I installed the post process package. This sounds ridiculous but happened because of some problems with version control. But anyway, the solution is very simple. Make sure you have the post process package installed, then remove the post process layer and add it back.
     
  21. tubaphc

    tubaphc

    Joined:
    Mar 7, 2017
    Posts:
    4
    worked thanks
     
  22. tolgakaranlik

    tolgakaranlik

    Joined:
    Oct 8, 2020
    Posts:
    7
    100% working solution (2021.3.0f1)
     
  23. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    faced the same issue, you can select camera post-process layer then switch to debug mode in the inspector and assign ref to resources by hands
    upload_2022-8-9_16-3-19.png
     
    pixelgm, rmolotov, Kobaltic1 and 2 others like this.
  24. jorge_acm

    jorge_acm

    Joined:
    Dec 12, 2020
    Posts:
    6
    Hi,
    Solution, in my case I had imported a package from my other project, the camera came with Post-processing, and when installing the post-processing again, there was an error, which was already mentioned in the question, the solution was, eliminate the post-processing of the camera that came in the package that I had imported, and put the post-processing back on the camera, Note; the only drawback is to reconfigure the post-processing to the camera again. I hope it helps you
     
  25. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    I'm bringing back this post, because none of the mentioned solutions seems to work on my case.
    Premise: in Editor I don't have any errors, the errors are only in build, specifically on the Player-log.
    The thing is: the game works well, the post-process is working, but I still get an error log on the Player-log, which: 1) I guess slow down a bit the FPS, 2) creates a HUGE Player-log, especially after sometime you play (i.e. for 30 minutes playtime, it can get up to 100MB).

    Here the error:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2.   at UnityEngine.Rendering.PostProcessing.AmbientOcclusion.IsEnabledAndSupported (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x00096] in <641c028490bc4da9993fcb2aeea9578d>:0
    3.   at UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetLegacyCameraFlags (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x00024] in <641c028490bc4da9993fcb2aeea9578d>:0
    4.   at UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetupContext (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x000aa] in <641c028490bc4da9993fcb2aeea9578d>:0
    5.   at UnityEngine.Rendering.PostProcessing.PostProcessLayer.BuildCommandBuffers () [0x00095] in <641c028490bc4da9993fcb2aeea9578d>:0
    6.   at UnityEngine.Rendering.PostProcessing.PostProcessLayer.OnPreCull () [0x001f5] in <641c028490bc4da9993fcb2aeea9578d>:0
    7. UnityEngine.Camera:Render()
    8. PlanarReflections4.PlanarReflectionRenderer:RenderLegacyReflection(Camera)
    9. UnityEngine.Camera:FireOnPreCull(Camera)
    So, gameplay is not affected (besides maybe the FPS), but I get that huge Player.log.
    I'm using Unity 2021.1.3f1. Post Processing Package 3.2.0.

    I've tried the solutions listed above:
    - remove and re-apply postprocess volume and postprocess layer.
    - double check in the inspector - Debug mode if the PostProcessResources is correctly attached to the postprocess layer Resources.

    Note: apparently in the package manager where I've installed the Post Processing Package 3.2.0 it says "Recommended 3.1.1", and it suggests to "update" to version 3.1.1 (which is not an actual update). Is this due to a more stable version of the Post Processing Package? I wanted to try now v3.1.1 but I cannot access the Package Manager due to some issues with https://api.unity.com/v1/oauth2/authorize (feels like it's offline). But I'm not sure it'll fix my issues...

    Any hints are very welcome.


    EDIT: the service came back online, so I "updated" the Post Processing Package to 3.1.1 but I've the exactly same issue as before.
     
    Last edited: Dec 1, 2022
  26. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    Sorry for the bump... but really can't find a way out.
     
  27. Yany

    Yany

    Joined:
    May 24, 2013
    Posts:
    96
    My issue came the same way:

    I installed a package and it wanted to use PostProcess.
    I installed the PostProcess package.

    ...now those flooding errors coming...

    I just reopened the scene without any further tricks or restarting Unity.
    Post process works, errors nowhere.
     
  28. jonathanglitchers

    jonathanglitchers

    Joined:
    Jan 5, 2023
    Posts:
    8
    Still having these issues in 2023 with v3.2.2
    It eventually stopped spamming after restarting unity, deleting the camera and re-creating it...

    ... but then adding render textures broke it again.

    I don't really have the energy to tackle bugs in all the low quality poorly tested packages unity is pumping out, so thankfully old V1 post processing stack still works if you're having this issue. Not ideal, might not be right for you, but I just need a few frames.
     
  29. ostapgum02

    ostapgum02

    Joined:
    Feb 19, 2019
    Posts:
    2
    Reset "Post-process Layer" component in inspector
    upload_2023-10-13_22-17-22.png