Search Issue Tracker
By Design
By Design in 2023.3.X
Votes
0
Found in
2021.3.33f1
2022.3.15f1
2023.2.4f1
2023.3.0a18
Issue ID
UUM-58389
Regression
No
ScriptableObject.OnDestroy is not called after Respouces.UnloadUnusedAssets
Reproduction steps:
- Open the attached “ScriptableObjectTest.zip” project
- Open the “Assets/Scenes/NewScene.unity”
- Enter the Play Mode
- Observe the Console window
Expected result: 2 logs are outputted as the OnDestroy method is called on both the GameObject and ScriptableObject
Actual result: Only a single log from the GameObject’s OnDestroy call is outputted
Reproducible with: 2021.3.33f1, 2022.3.15f1, 2023.2.4f1, 2023.3.0a18
Reproducible on: M1 MacOS 14.0
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
- "Shader warning in 'Hidden/Light2D': implicit truncation of vector type" is thrown when building Universal 2D template
- AI Assistant breaks compilation of packages using System.Runtime.CompilerServices.Unsafe via auto-referencing
- Unity Hub checks the "Documentation" module by default on the 6.4 and 6.5 streams despite that it was unchecked with the previous installs
- Shortcut that toggles between Dopesheet and Curves Views in the Animation Window's Timeline is mislabed
- Property List Items Overlap onto the Property List's top edge when scrolling through a long Property List
Resolution Note:
This is a by-design behavior. Calling Destroy inside the OnDestroy callback means the object will be Destroyed in the next frame. However, UnloadUnusedAssets picks that object (since nothing holds it) and garbage collects it with other unused objects.
Workaround: Call DestroyImmediate() inside the OnDestroy to ensure the object will be destroyed before it is garbage collected.
Resolution Note (2023.3.X):
This is a by-design behavior. Calling Destroy inside the OnDestroy callback means the object will be Destroyed in the next frame. However, UnloadUnusedAssets picks that object (since nothing holds it) and garbage collects it with other unused objects.
Workaround: Call DestroyImmediate() inside the OnDestroy to ensure the object will be destroyed before it is garbage collected.