Debugging a build

Are there any tips / tutorials on how to debug your final build?

I have a custom shader and also camera post processing effects that work in the editor but do not work in the final build and have no idea how to debug.

Debugging on a device is the same concept as in the editor and is the same inside or outside of Unity or over the web or with multiplayer.

The differences between those are simply how much extra effort it takes and what information is easily accessible, versus what information may require you to actually write additional instrumentation.

But it’s still debugging: you need to find out WHAT is broken before you can reason about how it could possibly be fixed.


Standard blurb:

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS:

Or this answer for Android:

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Hey thx for reply Kurt. I think the problem is that my postprocessprofile file that I am loading in resources folder is not being included in build.

I found this in the dev log.

NullReferenceException: Object reference not set to an instance of an object
  at UnityEngine.Rendering.PostProcessing.AmbientOcclusion.IsEnabledAndSupported (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x000a8] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\Effects\AmbientOcclusion.cs:189 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetLegacyCameraFlags (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x0001b] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:822 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetupContext (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x000bc] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:917 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.BuildCommandBuffers () [0x000a4] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:564 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.OnPreCull () [0x00270] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:493 

(Filename: ./Library/PackageCache/com.unity.postprocessing@3.4.0/PostProcessing/Runtime/Effects/AmbientOcclusion.cs Line: 189)

And this is how I am adding it to my camera during runtime.

        p.view = p.head.AddComponent<Camera>();
        p.view.fieldOfView = 70f;
        p.view.nearClipPlane = 0.001f;
        p.view.farClipPlane = 22f;
        p.ppl = p.head.AddComponent<PostProcessLayer>();
        p.ppl.volumeLayer = LayerMask.GetMask("Camera");
        p.ppv = p.head.AddComponent<PostProcessVolume>();
        p.ppv.isGlobal = true;
        p.ppv.profile = Resources.Load<PostProcessProfile>("Misc/PostProcessing");
        p.ppl.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing;

I’m guessing unity sees that this file is not being referenced anywhere so it’s not including it in the final build. How do I tell unity to specifically include it?

For the shader problem… it’s a shader graph file. It’s not behaving the same way as in the editor for some reason, it’s clipping in and out of other geometry so I believe its a render queue issue? There’s just not a lot of info for me to go on here.

Hmm…

As per the rules of Resources.Load<T>(), that path Misc/PostProcessing must be under a Resources/ folder.

All things under a Resources/ folder will be included in a build.

Are you sure that’s where your nullref is???

I dunno man, it just repeats this in the log a bunch of times.

NullReferenceException: Object reference not set to an instance of an object
  at UnityEngine.Rendering.PostProcessing.AmbientOcclusion.IsEnabledAndSupported (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x000a8] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\Effects\AmbientOcclusion.cs:189 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetLegacyCameraFlags (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x0001b] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:822 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.SetupContext (UnityEngine.Rendering.PostProcessing.PostProcessRenderContext context) [0x000bc] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:917 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.BuildCommandBuffers () [0x000a4] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:564 
  at UnityEngine.Rendering.PostProcessing.PostProcessLayer.OnPreCull () [0x00270] in .\Library\PackageCache\com.unity.postprocessing@3.4.0\PostProcessing\Runtime\PostProcessLayer.cs:493 

(Filename: ./Library/PackageCache/com.unity.postprocessing@3.4.0/PostProcessing/Runtime/Effects/AmbientOcclusion.cs Line: 189)

I’m just building to windows and I have only one quality setting. I’m guessing it’s some kind of setting in the unity player that I need to flick on/off but I don’t know what it could be.

Perhaps it’s a unity bug? If I add a camera in the scene and give it post processing effects then that will show up but if I try to load my own in resources folder it does not.