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 mecanim::animation::TransformValuesFromClip when entering the Play Mode in a project with Animancer Pro v8
- Connection to Named Pipes fails when server and client are run
- Subgraph Block cannot be dragged and dropped to the workspace and it throws errors
- "Capsule" and "Cylinder" Shader Graph preview types can't be freely rotated
- Cubemap mipmaps display differently between Editor and Player when using custom mipmaps
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.