Search Issue Tracker
By Design
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
- [Android] [iOS] [UnityWebRequest] Requests with "UnityWebRequest" are open for SSL Proxying
- SetWindowsHookEx does not prevent Windows key input when Editor or Player Window is focused and Active Input Handling is set to “Input System Package (New)” or “Both”
- Crash on GetEffectiveBc7TextureCompressor() when loading and unloading all Assets in the Project
- Terrain Masks do not ignore the mipmap limit
- "Build And Run" the project for Web is allowed even though the directory for the non-default browser is not selected
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