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
- [HDRP] Text is rendered with artefacts when using STP and resolution scale is set a float value
- [Settings Search] Search results not matching search term correctly
- Crash on memcpy when opening a project that loads TSS files
- Multiple errors appear when compiling a ShaderGraph shader's code in a specific project
- TextMeshPro memory leak occurs when reloading the scene using Addressables
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