Search Issue Tracker

Won't Fix

Votes

0

Found in

2019.4

2020.3

2020.3.31f1

2021.2

2022.1

2022.2

Issue ID

1414339

Regression

No

Multiple GC allocations before calling AnimationEvent with no string parameters

Animation

-

How to reproduce:
1. Open the user's attached project "How to get rid of AnimationEvent GC Alloc.zip"
2. Open Window > Analysis > Profiler
3. Select the CPU Usage and Memory modules
4. Select the Raw Hierarchy from the module details pane dropdown menu
5. Press Play
6. Pause or exit Play mode
7. Locate the GC Allocated In Frame spike and search for Animator.FireAnimationEvents
8. Select the result and press the 'F' key
9. Expand the Animator.FireAnimationEvents field and observe GC.Alloc count

Expected result: No GC allocations happen
Actual result: Multiple GC allocations happen

Reproducible with: 2019.4.37f1, 2020.3.32f1, 2021.2.17f1, 2022.1.0b15, 2022.2.0a9

Note: GC allocation happens 1-2 frames before AnimationEvent

  1. Resolution Note:

    After some investigation the AnimationEvent is a class which is managed and containt some field that are also managed.
    We could save 16 byte out of 200 byte if the stringParameter is empty, but that would be an API changes which could break some existing project, the risk of regression in user project is too high compare to the small gain you get since anyway you will get a GC at some point.

    The workaround is to narrow down your method parameter to use only field that are not managed in the AnimationEvent.
    Animation events support method that take zero or one parameter. The parameter can be a float, an int, a string, an object reference, or an AnimationEvent. So if you want to avoid managed allocation stick to either method with zero parameter or one parameter of type float or int.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.