Search Issue Tracker
By Design
Votes
6
Found in
2017.1.0f3
Issue ID
930031
Regression
No
[docfix] .NET4.6 - C#6 - Null propagation operator does not work if variable is null
Reproduction steps:
1. Open the attached project
2. Open the scene
3. Press play
Expected: string "GO name: NAME IS NULL" is printed to debug console
Actual: UnassignedReferenceException is thrown
It works if the variable before Null propagation operator is not null though.
Reproduced on: 2017.1.0a6, 2017.1.0b2, 2017.1.0f3, 2017.2.0b2
Comments (2)
-
Rennan24
Oct 12, 2017 16:16
Yeah I kinda wish they would remove the fake null for UnityEngine.Objects, but then again it would break a lot of projects that do if( gameObject ) instead of if( gameObject != null )... but I don't use if( gameObject ) so my projects wouldn't break! :D
-
BlackPete
Jul 18, 2017 22:45
I have a feeling that Unity will say that this is "as designed" due to the use of a fake null for UnityEngine.Object types.
However, this violates the principle of least surprise, and this breaks the null propagation operator, which should be a valid C# 6 operator.
At the very least, the exception should be removed.
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
- VFX Graph particles are not culled when using URP and Frustum Culling is enabled on VFX Mesh Output
- Texture2D hash changes inside of an AssetBundle when rebuilding a SpriteAtlas bundle with an empty AssetPostprocessor Script enabled
- Aniso Level still applies when Generate MipMap is disabled in Texture Import Settings
- Mipmap Limit Groups long names are not truncated when creating a new Mipmap Limit Group with a long name
- “ArgumentException: Invalid double parameter.” error is thrown when Infinity is typed into the Fixed Timestep field
Resolution Note (2018.3.X):
Updated the Docs about our take on null propergation and null conditional operators, for UnityEngine.Object and friends