Null 'UniversalAdditionalCameraData' in VolumeDebugSettings.cs

Hello and thanks for the help/insight in advance!

I just upgraded to Unity 2022.1.1f1 and experienced the following Exception in UnityEngine.Rendering.DebugDisplaySettingsVolume. The issue is reproducible 100% within my project.

Thanks!!

Repo Steps:

  • Load project
  • Run game by pressing play button
  • Stop game by pressing stop button

Observed the following exception upon the play mode stopping:

  • MissingReferenceException: The object of type ‘UniversalAdditionalCameraData’ has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

  • In the Unity Scene View, objects no longer render as a result of the exception.

  • This exception now throws constantly in the Unity Editor and the Unity editor must be force-quit-and-restarted for the error to go away.

Notes:
It appears that there is a null entry in the additionalCameraDatas list of the VolumeDebugSettings class. This can be seen here:

Unity 2022.1 is unusable for me unit I can resolve this. My feeling is that this is a URP bug, thought it could be manifested by some unexpected configuration in my camera rig, or me accidentally clearing some sort of delegate by accident some where in my code. I did look over my stuff and it is pretty straight forward. I do make heavy use of multiple cameras and additive scenes.

My project is quite large 10Gigs so it may be hard to boil down a project that can reproduce this or upload a project file. Please advise if you feel this is a bug and how I should proceed, or if anyone has experienced/worked around this

Expected
Unity should not enter and inoperable state due.

Project Environment:
Unity 2022.1.1f1
Mac OSX 11.4
URP 13.1.8

Stack:

MissingReferenceException: The object of type 'UniversalAdditionalCameraData' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.Component.GetComponent[T] () (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Component.bindings.cs:42)
UnityEngine.Rendering.VolumeDebugSettings`1+<get_cameras>d__11[T].MoveNext () (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/VolumeDebugSettings.cs:64)
UnityEngine.Rendering.DebugDisplaySettingsVolume+WidgetFactory.CreateCameraSelector (UnityEngine.Rendering.DebugDisplaySettingsVolume data, System.Action`2[T1,T2] refresh) (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/DebugDisplaySettingsVolumes.cs:87)
UnityEngine.Rendering.DebugDisplaySettingsVolume+SettingsPanel..ctor (UnityEngine.Rendering.DebugDisplaySettingsVolume data) (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/DebugDisplaySettingsVolumes.cs:358)
UnityEngine.Rendering.DebugDisplaySettingsVolume.CreatePanel () (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/DebugDisplaySettingsVolumes.cs:394)
UnityEngine.Rendering.DebugDisplaySettingsUI+<>c__DisplayClass3_0.<RegisterDebug>b__0 (UnityEngine.Rendering.IDebugDisplaySettingsData data) (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/DebugDisplaySettingsUI.cs:36)
UnityEngine.Rendering.DebugDisplaySettings`1[T].ForEach (System.Action`1[T] onExecute) (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/DebugDisplaySettings.cs:90)
UnityEngine.Rendering.DebugDisplaySettingsUI.RegisterDebug (UnityEngine.Rendering.IDebugDisplaySettings settings) (at Library/PackageCache/com.unity.render-pipelines.core@13.1.8/Runtime/Debugging/DebugDisplaySettingsUI.cs:47)
UnityEngine.Rendering.Universal.UniversalRenderPipeline..ctor (UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset asset) (at Library/PackageCache/com.unity.render-pipelines.universal@13.1.8/Runtime/UniversalRenderPipeline.cs:191)
UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset.CreatePipeline () (at Library/PackageCache/com.unity.render-pipelines.universal@13.1.8/Runtime/Data/UniversalRenderPipelineAsset.cs:384)
UnityEngine.Rendering.RenderPipelineAsset.InternalCreatePipeline () (at /Users/bokken/buildslave/unity/build/Runtime/Export/RenderPipeline/RenderPipelineAsset.cs:10)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
2 Likes

I have also been seeing this issue intermittently in Unity 2022.1.2f1.
Seems like a fairly big issue to me since the scene and game views becomes unusable unless you do a full restart of the editor.
Any insight is much appreciated.

4 Likes

Thanks for replying @samanabo and sorry to hear this is manifesting for you as well and it is not just me.

I’ve since tired to isolate the issue by stripping my project. It happens at quite a high frequency but I am finding it hard to narrow down a deterministic reproduction step. I notice it on the first few times I press play of a freshly loaded project.

forcing a domain reload on play seems to allow the editor to self correct. The additionalCamera list is probably not serialized so it is reset to a new instance on reload. This isn’t a proper fix though as the editor is still non functional in-between plays and we need the fast iteration time of PlayModeOptions.

I figure something in my code could be worked around to try to avoid the issue until it is fixed properly in URP. lots of non-empirical observations but nothing concrete:

At first, i thought it could have to do with explicit calls from my code to GetUniversalAdditionalCameraData from he camera class. when GetUniversalAdditionalCameraData is called, an instance of GetUniversalAdditionalCameraData is enabled causing it to register with the UniversalRenderPipelineVolumeDebugSettings. the camera is properly removed when the OnDisable is called, however if the camera is Destroyed before the onDisable is called, then the a null entry could now be in the additionaCameraDatas list if additionalCameraDatas.Contains fails in UnRegisterCamera.

Commenting all calls to GetUniversalAdditionalCameraData seemed to fix the issue… or at least reduce the frequency of the issue. I was unable to replicate/isolate the issue in a new project so perhaps there are more things that are causing the issue in combination.

I tried to see if the null instance was the Main camera or the Scene View camera that was nulled. The debugger did not give me good insight into if the null inside the aditionalCameras list used to be the Scene View camera or the Main Camera. I deleted the Main Camera from my scene and pressed play to observer thet the issue was still manifesting. also When I hide the Scene View (be placing it as an inactive-tab (placed the tab. under the game tab as seen in the pic below), and pressed play, the issue would Not manifest. From these, I think I can inferm that the Scene View Camera is destroyed at some point before it can be properly removed from the additionalCameras List. Not sure if the Scene View camera is destroyed/recreated on play start/stops or whatever.

8178920--1065098--upload_2022-6-3_11-10-2.png
From what I recall, hiding the scene view before the editor enters play mode seems to fix the issue.

Again not conclusive and I was unable to isolate deterministic reproduction steps and unable get a solid work around. For now Im sticking to unity 2021.3.LTS. I would like to use the Tech stream as my game isn’t releasing until next year. I was hoping that 2022 solves or eventually solves some of the Reload Assemblies iteration time issues as Reload Assembiles stacks 6-8s on each recompile of our project.

Anyways I hope the URP team sees this and can commit or provide some insight into a work around or if this is a bug vs data/project configuration issue.

cass UniversalAdditionalCameraData
{
  void RegisterDebug()
        {
            if (!m_IsDebugRegistered)
            {
                UniversalRenderPipelineVolumeDebugSettings.RegisterCamera(this);
                m_IsDebugRegistered = true;
            }
        }

        void UnRegisterDebug()
        {
            if (m_IsDebugRegistered)
            {
                UniversalRenderPipelineVolumeDebugSettings.UnRegisterCamera(this);
                m_IsDebugRegistered = false;
            }
        }
}


class VolumeDebugSettings
{
[INDENT]/// <summary>
/// Register the camera for the Volume Debug.
/// </summary>
/// <param name="additionalCamera">The AdditionalCameraData of the camera to be registered.</param>
public static void RegisterCamera(T additionalCamera)
{
    if (!additionalCameraDatas.Contains(additionalCamera))
        additionalCameraDatas.Add(additionalCamera);
}

/// <summary>
/// Unregister the camera for the Volume Debug.
/// </summary>
/// <param name="additionalCamera">The AdditionalCameraData of the camera to be registered.</param>
public static void UnRegisterCamera(T additionalCamera)
{
    if (additionalCameraDatas.Contains(additionalCamera))
        additionalCameraDatas.Remove(additionalCamera);

}[/INDENT]
}
1 Like

I’m getting the exact same thing.

Unity 2022.1.3 Apple Silicon
URP 13.1.8
macOS 12.3.1

Curious to see that @slippyfrog is also on a Mac. Maybe it’s a Mac issue? @samanabo are you also on a Mac? And running Apple Silicon?

Has anyone filed a bug with Unity yet?

2 Likes

@Somnesis Thanks for chiming in but sorry to hear you are getting this too. I was really looking forward to migrating to 2022 but this is a blocker.

Im happy to file a bug for in the next few days and can probably strip down a project that they can repo the issue with.

I’m running on an iMac with i7 processor and not that fancy Apple Silicon stuff :slight_smile:

It could very well be a Mac issue as maybe that’s why we are not seeing more people report the issue.

Are you guys using Highlight Plus (asset by Kronnect). That asset seem to do some custom render pass stuff and but is well written. I thought the issue could have perhaps been caused by something going on in there as it does invoke GetUniversalAdditionalCameraData which triggers camera being added to the additionalCamera list.

1 Like

I AM using a mac as well, but not Apple Silicon.
I’m not using Highlight Plus, and I have not filed a bug report since I cannot consistently reproduce it.
I’d be happy to test anything out… or look into it more if there are any ideas on how…

1 Like

Thanks for the additional info @samanabo

I checked out and ran my project on a Win 11 machine running Unity 2022.1.4 with URP 13.1.X and observer the null UniversalAdditionalCameraData issue. As such, this issue is not specific to Mac OS and can be confirmed as a universal defect.

I’m surprised not more people have encountered this. Moving to Unity 2022.1.X isn’t a huge priority for me right now, but I’ll look to submit a stripped down project with a bug report over the next little but when I get chance. If any one would rather file a bug report sooner, just let me know on this thread so I don’t double post.

2 Likes

I am using highlight plus and we also have our own custom render feature for our own shader.

@samanabo do you have any render features enabled in your URP renderer?

And @slippyfrog do you have any other render features besides highlight plus?

Maybe the bug has to do with having custom render features. Though that would be the entire point of URP, so that feature should work :smile:

Okay so I removed the reference to GetUniversalAdditionalCameraData() in HighlightPlus and now the error is gone! So that was definitely the culprit for me :slight_smile:

@Somnesis

Fantastic! Glad the workaround works for you, but does that mean that HighlightPlus is not working correctly now? :slight_smile:

I feel like the culprit is GetUniversalAdditionalCameraData begin called from a custom render pass feature.
I wasn’t however able to isolate the issue by creating a new project with just URP and Highlight plus but I think I might try again.

Highlight plus is pretty robust and widely used so I still feel this is a URP bug. Unfortunately I haven’t had time to file this as a bug with Unity as I’m pretty swamped these days.

If anyone gets a chance please feel free to file it!

I’m using the 2D renderer with no custom renderer features.
I do have post processing enabled, and I have the “Camera Sorting Layer Texture” enabled.
Based on the errors shown, my best guess is an issue with post processing but I’m not really sure. Happy to look into any part of this.

It seems like I am able to make the error occur when the game view is set to “maximize”. If I take the following steps I can reproduce it consistently:

  • Set the game view to maximize

  • Start playing the game

  • Right click on the game view tab and un-maximize

  • Stop playing the game

  • Start playing the game again

  • Observe the game view and scene view are blank and the error occurs

I get the same error and it’s clearly the scene camera. When stopping the player it seems to not properly unregister itself.

1 Like

Experiencing the same issue here. Very frustrating.

Using Unity 2022.1.8f1, using URP, and also using a single custom (albeit basic) ScriptableRenderPass.

Same thing happening to our team. 2D renderer, no customization, medium sized project, some plugins but nothing that would obviously manipulate URP. 2022.1.7f

Same issue, anyone found a workaround?

This also happened to me after updating a 2021 project to 2022.1.11f1. For me, I get a "MissingReferenceException: The object of type 'UniversalAdditionalCameraData' has been destroyed but you are still trying to access it." constantly spamming the editor whenever I have a scene open. I’d love to know if anyone’s found a fix.

EDIT: It’s fixed if I turn on Domain Reloading in my editor settings. However, I had this option turned off to let me iterate on my game faster within the editor. Now I’d have to slog through 10-20 seconds of load time whenever I want to run my game. I’m switching back to 2021 for now until this issue is fixed.

1 Like

@Atlinux Yeah Domain Reload will force Unity to fix itself by clearing the members with corrupt entries.

Reflection time is severely impacted by this and 10-20 seconds load-on-play is not a viable workflow. I decided to stay on 2021.3.X until this issue is fixed because its just too much to work around.

This is defiantly an issue with the URP but Unity guys have not chimed in and I’m a bit too busy to file a bug and I’m find working with 2021.3.X for the foreseeable future.

As a work around, could you force domain reload when exiting-out-of-play-mode? Its still a long pause for the editor, but for me I usually jump back into the ide/code as soon as I stop play. Could you also have a button that triggers RequestScrptReload so you can manually call it. its not great but better than nothing.

Alternatively, you might be able to clear the list with the null entry through reflection (I think we can grab the handle the the instances with the list that has the null camera data entry). its also ugly but it could potentially avoid a domain reload – assuming the rest of the data is not in an indeterminate state.

1 Like

This still happens for me after updating to 2022.1.10f1 and I can generally reproduce the problem when I have the game view set to maximize, and while the game is running I right click and un-maximize the game view.

As for a workaround, I took the suggestion from @slippyfrog and created the attached script to quickly reload the domain/scripts. It is far from ideal… but it does save you reloading the whole editor.

8329368–1094295–RequestScriptReloads.cs (240 Bytes)

3 Likes

Same issue here on 2022.1.10f1.

As of today, on 2022.1.11f1 i am also getting this. just out of nowhere, was building in scene view hit play, then boom all gone, both scene and game camera not working until editor reboot.,

1 Like