Search Issue Tracker
By Design
Votes
3
Found in
2019.4
2019.4.28f1
2020.3
2021.1
2021.2
2022.1
Issue ID
1344907
Regression
No
"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
Notes:
- 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
-
VoodooDetective
Jun 28, 2021 19:04
I just wanted to add, the "non-blittable data" error is happening in that reproduction because the "B" class needs to have this attribute on it:
[StructLayout(LayoutKind.Sequential)]
That has nothing to do with the bug being reported though.
-
VoodooDetective
Jun 25, 2021 18:53
This breaks "Programmer Instrument" in FMOD.
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
- "EndLayoutGroup: BeginLayoutGroup must be called first" error is thrown when changing Shader Precision Model from the Build Profiles window
- White artifacts/outlines are visible in the Garden Scene when viewing at meshes from a distance
- Shader warnings "Sprite-Unlit-Default" are thrown after building 2D Platrformer Microgame Template
- [Android] HLSL shader becomes corrupted when running on an Android device
- Missing spaces in "Welcome to VR Mutiplayer Template Project" Welcome Dialog window
Resolution Note (2022.1.X):
IL2CPP follows the documented behavior for GCHandle.Alloc with GCHandleType.Pinned - it will throw an ArgumentException if passed a non-blittable type.