Search Unity

Bug Lights2D still allocating garbage per frame?

Discussion in '2D' started by Flag74, May 13, 2023.

  1. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
  2. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Hi @Flag74, this shouldn't be happening. The fix removed GC.Allocs in a different part of Light2D. Are you able to share your project, so I can take a look.
     
  3. Flag74

    Flag74

    Joined:
    May 31, 2017
    Posts:
    128
    Digging into it I found that animating the Falloff property of the those kind of Lights, it allocates garbage. (changing Intensity it's ok)
    Is it a normal behaviour?
    @kennyy_
    upload_2023-5-15_10-44-2.png
     
    Last edited: May 15, 2023
  4. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    Yes, this is intended if you're modifying the fall off size at runtime. The freeform light's shape mesh and fall off needs to be regenerated. I'd recommend having a fixed fall off size and modifying the Falloff Strength property instead, so you won't incur the GC.Allocs.
     
    Flag74 likes this.
  5. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    It looks like the bug is still exist in Unity 2023.1.3f1. 2Dlights generates GC no matter what.

    When examine the code and follow where gc occure:

    upload_2023-7-8_11-23-14.png

    GC seems to generate on call stack on NeedsColorIndexBaking check. My light has not changed at all so the actual result of hasChanged or forceUpdate is false, but just checking NeedsColorIndexBaking causes GC to occur. @kennyy_
     
  6. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    @castor76 Thanks for catching it. The allocations have already been fixed, and I'll backport it back to 2023.1.
     
  7. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    @kennyy_ Great news. Any idea which version will have the fix? My bug report does not respond to my feedback anymore so I can't tell. IN-46889
     
  8. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    96
    It will be landing in the Unity 2023.1.8f1 release.