Search Issue Tracker
In Progress
Fix In Review for 6000.0.14f1
Votes
1
Found in
2023.2.19f1
6000.0.0b15
7000.0.0a1
Issue ID
UUM-69806
Regression
No
HDRP LightLateUpdate allocates every frame for each light in the scene when in Play Mode
Reproduction steps:
1. Open the “ReproProject“ project
2. Open the “Assets/OutdoorsScene“ scene
3. Open the Profiler window (Window > Analysis > Profiler)
4. Enter Play Mode
5. Select any frame in the Frame chart in the Profiler window
6. Expand the “PlayerLoop“ in the Hierarchy of the Profiler window
7. Observe the “LightLateUpdate“ allocations in the Hierarchy of the Profiler window
Expected result: No allocations in the LightLateUpdate
Actual result: 25 allocations in the LightLateUpdate
Reproducible with: 2023.2.19f1, 6000.0.0b15
Couldn’t test with: 2021.3.37f1, 2022.3.25f1
Reproducible on: Windows 11 Pro (22H2)
Not reproducible on: No other environment tested
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Search field in UI Builder's Library has no character limit
- Changing the value in UI Builder by dragging increases it by a few thousand points when reaching the borders of the screen
- ARM64 architecture DLL incorrectly copied instead of x64 when building for Windows x64
- Crash on TypeTreeIterator::GetNode when opening a specific folder
- Crash on WriteSerializedAssetsV2 when (re)entering the Play Mode in a specific project when IEnumerator Start() is used
Daniel-Dorotik
Jun 05, 2024 17:37
Hello,
I have encountered the same issue with memory allocations in the LightLateUpdate method and can confirm that it is reproducible in Unity 2023.2.20f1 with HDRP package version 16.0.6, as well as Unity 6 Preview (6000.0.4f1) with HDRP package version 17.0.3.
Upon further investigation, I found that the source of allocations is within the HDAdditionalLightData.TickLateUpdate method. Specifically, the line int idx = directionalLights.FindIndex((x) => ReferenceEquals(x, lightData)); causes allocations due to the lambda expression capturing the lightData variable.
To resolve this issue, I replaced the lambda expression with an explicit for loop, as shown below:
else if (lightData.legacyLight.type != LightType.Directional)
{
for (int dirLightIndex = 0; dirLightIndex < directionalLights.Count; dirLightIndex++)
{
if (ReferenceEquals(directionalLights[dirLightIndex], lightData))
{
directionalLights.RemoveAt(dirLightIndex);
break;
}
}
}
This change eliminates the need for a closure and the associated delegate creation, preventing memory allocations in this part of the code. In the Profiler, these allocations show up under LightLateUpdate, and activating the Call Stacks functionality reveals that they originate from HDAdditionalLightData.TickLateUpdate.