Skip to content

Commit a4e44a8

Browse files
Fixed an exception occuring when a camera doesn't have an HDAdditionalCameraData (1254383). (#846)
Co-authored-by: sebastienlagarde <[email protected]>
1 parent 6c31f92 commit a4e44a8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
680680
- Fixed AxF handling of roughness for Blinn-Phong type materials
681681
- Fixed AxF UI errors when surface type is switched to transparent
682682
- Fixed a serialization issue, preventing quality level parameters to undo/redo and update scene view on change.
683+
- Fixed an exception occuring when a camera doesn't have an HDAdditionalCameraData (1254383).
683684

684685
### Changed
685686
- Improve MIP selection for decals on Transparents

com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Camera/HDCameraEditor.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using UnityEngine.Assertions;
3+
using UnityEngine.Rendering;
34
using UnityEngine.Rendering.HighDefinition;
45
using System.Collections.Generic;
56
using System.Linq;
@@ -89,14 +90,24 @@ public void RemoveComponent(Camera camera, IEnumerable<Component> dependencies)
8990
[MenuItem("CONTEXT/Camera/Reset", false, 0)]
9091
static void ResetCamera(MenuCommand menuCommand)
9192
{
92-
GameObject go = ((Camera)menuCommand.context).gameObject;
93+
// Grab the current HDRP asset, we should not be executing this code if HDRP is null
94+
var hdrp = (RenderPipelineManager.currentPipeline as HDRenderPipeline);
95+
if (hdrp == null)
96+
return;
9397

98+
GameObject go = ((Camera)menuCommand.context).gameObject;
9499
Assert.IsNotNull(go);
95100

96101
Camera camera = go.GetComponent<Camera>();
97-
HDAdditionalCameraData cameraAdditionalData = go.GetComponent<HDAdditionalCameraData>();
98-
99102
Assert.IsNotNull(camera);
103+
104+
// Try to grab the HDAdditionalCameraData component, it is possible that the component is null of the camera was created without an asset assigned and the inspector
105+
// was kept on while assigning the asset and then triggering the reset.
106+
HDAdditionalCameraData cameraAdditionalData;
107+
if ((!go.TryGetComponent<HDAdditionalCameraData>(out cameraAdditionalData)))
108+
{
109+
cameraAdditionalData = go.AddComponent<HDAdditionalCameraData>();
110+
}
100111
Assert.IsNotNull(cameraAdditionalData);
101112

102113
Undo.SetCurrentGroupName("Reset HD Camera");

0 commit comments

Comments
 (0)