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
- Out-of-bounds memory access with multiple CanvasRenderers under a Canvas when using Mesh API
- Inspector tries to access file after it was deleted when the file was locked in Inspector window
- Changing Transform values in Search window Inspector loses focus while dragging and stopping mouse without releasing dragging action
- Saving changes on the dirty VFX Graph during the Play mode throws "The referenced script (Unknown) on this Behaviour is missing!" warnings
- VFX Graph Debug Info overlaps the "Initialize" block debug info by default
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.