# Unity, getting a null reference after baking in occlusion

I have imported models from blender into Unity, also checked generate lightmap UV's in the import settings.

Then I set the model as static and baked the scene. After that when the object is disappearing because of the Occlusion I get an Error:

NullReferenceException: Object reference not set to an instance of an object UnityEngine.PostProcessing.BuiltinDebugViewsComponent.GetCameraEvent () (at Assets/PostProcessing/Runtime/Components/BuiltinDebugViewsComponent.cs:137) UnityEngine.PostProcessing.PostProcessingBehaviour.TryExecuteCommandBuffer[BuiltinDebugViewsModel] (UnityEngine.PostProcessing.PostProcessingComponentCommandBuffer1 component) (at Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs:444) UnityEngine.PostProcessing.PostProcessingBehaviour.OnPreRender () (at Assets/PostProcessing/Runtime/PostProcessingBehaviour.cs:166) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

If I double click on the Error it brings up the Script named:

BuiltinDebugViewsComponent.cs

and shows the error on the following line 137:

    public override CameraEvent GetCameraEvent()
{
return model.settings.mode == Mode.MotionVectors
? CameraEvent.BeforeImageEffects
: CameraEvent.BeforeImageEffectsOpaque;
}


Well this might be a easy question but how do I check if the var model != null to workaround the error, I found out that this error occurs in the older versions of Unity.

I tried putting if(model != null) above the line but that gives me also a error, could someone help me on this?

• "I tried putting if(model != null) above the line but that gives me also a error" cool! Show us what you tried and what specific error you got. – DMGregory Apr 7 at 13:38
• if I do the if(model != null) above the line I get this error: Assets/PostProcessing/Runtime/Components/BuiltinDebugViewsComponent.cs(103,13): error CS0161: UnityEngine.PostProcessing.BuiltinDebugViewsComponent.active.get': not all code paths return a value The "get" isn't returning now why is this and what can I do? – Daniel Apr 7 at 14:21
• That error tells you that you need to provide a return value for that case, like if(model == null) return false; – DMGregory Apr 7 at 14:26
• well it solved the first one now it moved to another function: I will edit my thread look it up there – Daniel Apr 7 at 14:29
• It sounds like the scripts you're using are strongly expecting that the objects you're using them with should not be null. Rather than plug all the holes one by one, it might be better to investigate why they assume it will be non-null, and what's breaking that assumption. – DMGregory Apr 7 at 14:30