Search Issue Tracker
"The script '<script>' could not be instantiated!" error produced in build when a script creates an object that calls GC.Handle
Steps to reproduce:
1. Open the attached project ("1344907.zip")
2. Open "SampleScene"
3. Make sure IL2CPP is selected as the current Scripting Backend (Edit -> Project Settings -> Player -> Scripting Backend)
4. Build and run the project
5. Open the Player logs (https://docs.unity3d.com/Manual/LogFiles.html)
Expected results: No errors are produced, script is instantiated
Actual results: "The script '<script>' could not be instantiated!" error is produced
Reproducible with: 2019.4.28f1, 2020.3.11f1, 2021.1.14f1, 2021.2.0b2, 2022.1.0a1
Didn't test on 2018.4 because couldn't find Player logs
- The full scenario is that a MonoBehaviour script creates an object that calls GC.Handle for another object containing just a variable declaration
- Calling GC.Handle on the same class but in start instead of creating an object produces this error:
"ArgumentException: Object contains non-primitive or non-blittable data."
- Doesn't reproduce with Mono
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- [2D] Texture 2D Array preview looks corrupted when Mip Map Filtering is set to Box at different Mip levels
- [HDRP][XR] Shadergraph tessellation work differently with XR
- Not uploading texture to the 3D API / GPU during importing has regressed StreamingTests.TextureLoad test in performance
- [Physics] The capsule jitters falling into the cracks between triangle edges
- ArgumentOutOfRangeException is thrown when right-clicking certain Hierarchy window items during Play Mode exit process