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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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.