Search Issue Tracker
By Design
By Design in 2023.1.X
Votes
0
Found in
2020.3.40f1
2021.3.10f1
2022.1.17f1
2022.2.0b8
2023.1.0a12
Issue ID
UUM-16595
Regression
No
"InitializeOnLoad" method runs before Asset Database is ready when reimporting with the "Reimport All" option
How to reproduce:
1. Open the attached user project
2. Select the Assets folder, right-click on the folder and press “Reimport All“
Expected result: Message “AssetDatabase.FindAssets: 1“ logged in the Console
Actual result: Message “AssetDatabase.FindAssets: 0“ logged in the Console
Reproduced with: 2020.3.40f1, 2021.3.10f1, 2022.1.17f1, 2022.2.0b8, 2023.1.0a12
Reproduced on: macOS (12.5)
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
- Texture2D hash changes inside of an AssetBundle when rebuilding a SpriteAtlas bundle with an empty AssetPostprocessor Script enabled
- Aniso Level still applies when Generate MipMap is disabled in Texture Import Settings
- Mipmap Limit Groups long names are not truncated when creating a new Mipmap Limit Group with a long name
- “ArgumentException: Invalid double parameter.” error is thrown when Infinity is typed into the Fixed Timestep field
- GameObject becomes gray when using HDRP and STP together on macOS
Resolution Note:
This is expected behaviour. From the manual entry for 'InitializeOnLoadAttribute' :
"Asset operations such as asset loading should be avoided in InitializeOnLoad methods. InitializeOnLoad methods are called before asset importing is completed and therefore the asset loading can fail resulting in a null object. To do initialization after a domain reload which requires asset operations use the AssetPostprocessor.OnPostProcessAllAssets callback. This callback supports all asset operations and has a parameter signaling if there was a domain reload."
https://docs.unity3d.com/ScriptReference/InitializeOnLoadAttribute.html
Resolution Note (2023.1.X):
This is expected behaviour. From the manual entry for 'InitializeOnLoadAttribute' :
"Asset operations such as asset loading should be avoided in InitializeOnLoad methods. InitializeOnLoad methods are called before asset importing is completed and therefore the asset loading can fail resulting in a null object. To do initialization after a domain reload which requires asset operations use the AssetPostprocessor.OnPostProcessAllAssets callback. This callback supports all asset operations and has a parameter signaling if there was a domain reload."
https://docs.unity3d.com/ScriptReference/InitializeOnLoadAttribute.html