Search Issue Tracker
Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.
Postponed
Votes
3
Found in
4.3.4f1
Issue ID
592094
Regression
No
Object member initializers in C# scripts ignores values that are same default value of that type
Example:
public class SomeClass
{
public int SomeValue = 1;
}
SomeClass a = new SomeClass { SomeValue = 0 };
Debug.Log(a.SomeValue); // 1
To reproduce:
1) Open the attached scene and load 'test' scene
2) Play the scene and go to console tab
3) Notice that second line outputs 'b: 1 3 hehe' instead of 'b: 0 3 ', even though it is written in the code that it should change this value.
Comments (1)
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
- Crash on GUIManager::DoGUIEvent when focusing on the Game view window on a specific project
- Asset creation in the Project Browser is not always undone/inconsistent when the undo shortcut is pressed right after creating an asset
- JobTempAlloc memory leak warning is thrown when the Player is shut down
- Graphics State Collection warm-up does not work when using with Addressables Shaders
- "Baked Shadow Radius" field is visible but inactive when when the Shadow Type is set to "Hard Shadows" under the Light Component
Neat-Sketch
Aug 18, 2015 15:41
I encountered this issue while working on my project too. It's a serious bug because a buggy programming language feature can potentially lead to even more serious problems.
Here is another example of this issue. Just attach the following script to any active GameObject. You will see the result in the log.
using UnityEngine;
public class MyClass {
public int a = -1;
public int b = -1;
public int c = -1;
public int d = -1;
}
public class TestScript : MonoBehaviour {
void Start () {
MyClass myObject = new MyClass {
a = -1,
b = 0,
c = 42,
d = 5
};
Debug.Log (myObject.a); // prints -1
Debug.Log (myObject.b); // prints -1 (Should be 0 !!!)
Debug.Log (myObject.c); // prints 42
Debug.Log (myObject.d); // prints 5
}
}