Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2020.3
2020.3.14f1
2021.2
2022.1
Issue ID
1383018
Regression
No
Variable values are not assigned when a Monobehaviour script has a constructor requiring a parameter
Reproduction steps:
1. Open the attached project "Case_1383018" and load Scene "SampleScene"
2. Enter Play Mode
3. Observe the Console
Expected result: "someTestString" is printed in the Console
Actual result: "Null" is printed in the Console
Reproducible with: 2019.4.33f1, 2020.3.23f1, 2021.2.4f1, 2022.1.0a16
Notes:
- Issue is not reproducible when using a parameterless constructor
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
- "SupportsRandomWriteOnRenderTextureFormat()" shows "False" when executed on 2023.2 and 6000.0 streams
- Size of ShadowCaster2D with Casting Source set to a Collider increases when RigidBody2D is attached to the GameObject
- GameObjects with a material derived from a Custom Lighting Surface Shader are displayed as skewed on quads when the Camera's Width and Height properties of the Viewport Rect are lower than 1
- Warning 'Unable to find player assmebly' is thrown when building some Project Templates
- ArgumentOutOfRangeException when manipulating the Project Settings search bar
Resolution Note (2022.1.X):
This is actually by design:
Instantiation of MonoBheviours is done by the engine in a very special way that can't be customized for performance reasons. One of the effects is that we never call parameterized constructors even if no default constructors exist.
Also default constructors are called in non-totally obvious ways, so users should refrain from declaring constructors on Behaviours at all (see http://ilkinulas.github.io/development/unity/2016/05/30/monobehaviour-constructor.html)