Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2020.3
2021.2
2021.2.3f1
2022.2
Issue ID
1384425
Regression
No
Asset Database operations not working correctly when invoked from [InitializeOnLoadMethod] after rebuilding the project database
Reproduction steps:
1. Open the attached user's project
2. Notice that 'Data (Data)' is printed in the console
3. Close the project
4. Delete the Library folder from the project directory
5. Open the project again
Expected result: 'Data (Data)' is printed in the console
Actual result: 'Null' is printed in the console
Reproducible with: 2019.4.36f1, 2020.3.30f1, 2021.2.13f1, 2022.2.0a5
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:
This is expected behaviour. Asset Operation in InitializeOnLoad should be avoid because this is called before asset importing is completed. In 2021.2 a variant of the OnPostprocessAllAssets callback got introduced that includes a didDomainReload parameter. This callback is safe for asset loading.
https://docs.unity3d.com/2021.2/Documentation/ScriptReference/AssetPostprocessor.OnPostprocessAllAssets.html
It is also mentioned in the doc that asset operation in InitalizeOnLoad should be avoided:
https://docs.unity3d.com/2021.2/Documentation/ScriptReference/InitializeOnLoadAttribute.html