Hi all!
What does it means the Vector3? in:
[SerializeField] private Vector3? _someAttribute;
(I know what a Vector3 is , but I didn’t get the question mark on it)
And where can I find some documentation about it?
Thanks in advance!
Hi all!
What does it means the Vector3? in:
[SerializeField] private Vector3? _someAttribute;
(I know what a Vector3 is , but I didn’t get the question mark on it)
And where can I find some documentation about it?
Thanks in advance!
It’s a C# operator that’s a shorthand for Nullable types.
Normally, value types such as int, float, bool, and structs like Vector3 cannot be null.
Turning them into a Nullable type allows them to be null.
Everything that @Vryken said above is spot-on, and I want to add that one purpose for that ability is if you want a way to say “This data isn’t valid yet.” In some cases you could use zero or other special sentinel values that mean “data not valid yet,” but sometimes every value is valid, so this gives you a way to have every value AND an extra value that says “I don’t have a value yet.”
To use it where a Vector3 is expected, you just have to cast it:
if (_someAttribute != null)
{
transform.position = (Vector3)_someAttribute;
}
(just adding onto your snippet above).
Really thanks @ @Vryken and @Kurt-Dekker , it helps a lot!!