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
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
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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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.