NullReferenceException: Object reference not set to an instance of an object
- NullReferenceException: Object reference not set to an instance of an object
- 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)
- UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetLegacyCameraFlags (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:696)
- UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetupContext (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:781)
- UnityEngine.Rendering.PostProcessing.PostProcessLayer.BuildCommandBuffers () (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:468)
- UnityEngine.Rendering.PostProcessing.PostProcessLayer.OnPreCull () (at Library/PackageCache/com.unity.postprocessing@2.1.3/PostProcessing/Runtime/PostProcessLayer.cs:402)
导入新场景到工程里时报空引用异常,是因为PostProcess版本变化,导致PostProcessLayer组件丢失PostProcessResources引用资源。
PostProcessLayer组件执行Reset,然后重新指定Layer就可以了。
或者删除旧组件,重新添加PostProcessLayer也能解决问题。
unity论坛上有个用代码调用Init的也是同样的道理:初始化PostProcessResources
论坛地址:Post Process Stack NullRefferenceException - Unity Forum