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.
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
- The Editor becomes unresponsive and memory allocation errors are spammed in the Console when Generating Lightning
- Crash on BatchApplyPropertiesFromSourceAssetDB when opening a specific project
- Scene view Camera cannot be moved with WASD/QE keys when the Right Mouse Button is held down and the Mouse is not moved
- Crash when calling default interface method from virtual method with same name
- [Android] Unity does not include the ".aab" extension for an AppBundle when it is built via script with the buildPlayerOptions.locationPathName = "AppName.apk" and EditorUserBuildSettings.buildAppBundle = true
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
}
}