C# variable declaration default values

I’m still learning C#, though I have years of programming experience with C++, ActionScript, etc. I’m confused about default values of variables at declaration.

For instance:

private Vector3 _position;

From what I’ve read, C# should initialize _position to null until I assign it a value. But in Unity, that variable will have an instance of Vector3 already assigned.

Is this “automatic” instantiation something added to Unity as a convenience, or am I misinformed about the expected behavior for C# in this case?

Vector3, being a struct, is a value type, like an int or a double. As such, all its’ fields get set to default values based upon the fields type.

If you where using a reference type, like an Object or a Rigidbody (or pretty much anything that refers to a class), then the variable used would equal null.

Oohhhhh. :slight_smile: I thought Vector3 was a class. Thanks for the clarification!