Search Issue Tracker
By Design
Votes
0
Found in
2020.2.0a18
2020.3
2020.3.17f1
2021.1
2021.2
2022.1
Issue ID
1364561
Regression
Yes
Multiple and different SessionStates are returned when InitializeOnLoadMethodAttribute is called
Steps to reproduce:
1. Create a new project and add the attached "TestScript.cs" to the Asset folder
2. In Unity Editor's Project window right-click on "TestScript.cs" and select Reimport
3. Go to the project's folder in file explorer, then open "OnInitRuns.txt" and observe multiple lines added
4. Close "OnInitRuns.txt" and then delete it
5. In Unity Editor select Testing > Set Session State
6. Click Reimport on "TestScript.cs" again
7. Go to the project's folder in file explorer, then open "OnInitRuns.txt" and observe
Expected result: multiple lines which all read "HasBeenSet"
Actual result: one line reads "HasBeenSet" and another/others read "HasNOTBeenSet"
Reproducible with: 2020.2.0a18, 2020.3.21f1, 2021.1.25f1, 2021.2.0b16, 2022.1.0a12
Not reproducible with: 2019.4.31f1, 2020.2.0a17
Notes:
- in 2022.1.0a12 three lines get written to "OnInitRuns.txt", while in the other Streams only two get written
- issue is not reproducible after closing and reopening the project, however, if you alter "TestScript.cs" either by renaming it or changing its contents, the issue reappears
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
- Crash on GUIManager::DoGUIEvent when focusing on the Game view window on a specific project
- Asset creation in the Project Browser is not always undone/inconsistent when the undo shortcut is pressed right after creating an asset
- JobTempAlloc memory leak warning is thrown when the Player is shut down
- Graphics State Collection warm-up does not work when using with Addressables Shaders
- "Baked Shadow Radius" field is visible but inactive when when the Shadow Type is set to "Hard Shadows" under the Light Component
Resolution Note:
This is expected behavior. In 2020.2 we moved creation of previews into a separate process... that process is starting up the same C# domain as the editor and therefore also calling InitializeOnLoad.
UnityEditor.Experimental.AssetDatabaseExperimental.IsAssetImportWorkerProcess()
can be used to tell if you are running in a worker or in the editor. It will eventually be moved out of experimental of course.