Skip to content

Commit 6b0ada6

Browse files
ApoorvaJEvergreen
authored andcommitted
Avoid HDRP exception caused during async scene load
Bug fix for [UUM-58831](https://jira.unity3d.com/browse/UUM-58831) HDRP manually subscribes to the player loop callback and calls the tick function. This can throw a null reference exception during async scene loads where the component is initialized, but the parent GameObject is not. This PR fixes this null reference exception.
1 parent 092df02 commit 6b0ada6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Light/HDAdditionalLightData.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,6 +2748,20 @@ internal static void TickLateUpdate()
27482748
{
27492749
HDAdditionalLightData lightData = allAdditionalLightDatas[i];
27502750

2751+
// HDRP manually subcribes to the player loop callback and calls the tick function. This can trigger an
2752+
// edge case during async scene loads where the component is initialized, but the parent GameObject is
2753+
// not. In this case, we simply skip the tick logic. This is in a try block because there's no other
2754+
// way. Simply accessing the .gameObject member calls a getter that will throw a null ref exception in
2755+
// this invalid state.
2756+
try
2757+
{
2758+
var go = lightData.gameObject;
2759+
}
2760+
catch (Exception)
2761+
{
2762+
continue;
2763+
}
2764+
27512765
if (lightData.cachedLightType != lightData.legacyLight.type)
27522766
{
27532767
// ^ The light type has changed since the last tick.

0 commit comments

Comments
 (0)