Search Issue Tracker
By Design
Votes
11
Found in
2017.4.0f1
2018.4.0f1
2019.1.0a1
2019.2.0a1
2019.2.0f1
2019.3.0a1
Issue ID
1174400
Regression
No
OnDisable and OnDestroy methods are not called when a ScriptableObject is deleted manually in Project window
How to reproduce:
1. Open attached 'project-1174400.zip' project
2. In Editor select 'Test' > 'Create and Save'
3. Delete 'New TextAsset' in Project window
4. Observe Console window
Expected result: 'OnDisable' and 'OnDestroy' methods are called
Actual result: 'OnDisable' and 'OnDestroy' methods are not called
Reproducible with: 2017.4.31f1, 2018.4.6f1, 2019.1.14f1, 2019.2.1f1, 2019.3.0a12
Notes:
1) Creating an instance of ScriptableObject and destroying it using 'DestroyImmediate' right afterward calls 'OnDisable' and 'OnDestroy' ('Test' > 'Instantiate and Destroy')
2) Using 'Resources.UnloadAsset' calls 'OnDisable', however, it does not call 'OnDestroy' nor does it destroy the created asset
-
Kwahusss
May 11, 2021 09:05
Please fix this bug or update the ScriptableObject documentation.
-
futurlab_peterh
Nov 02, 2020 10:51
If this is "by design" then you need to fix the design.
When we add logic that should be processed on those events we shouldn't be caring whether the ScriptableObject got destroyed from a script or manually, the fact remains it got destroyed and we want to do something when that happens.
-
afrotsukuyomi
Feb 23, 2020 02:45
Has someone found a workaround to this?
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:
OnDisable and OnDestroy methods are called when object is destroyed and released from memory. When calling DestroyImmediate on object, both callbacks will be called. Although, they're not called when correspoding asset file is deleted from project browser, because they still can be referenced in memory. If asset deletion detection is needed AssetModificationProcessor.OnWillDeleteAsset can be used.