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)

  1. 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

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.