For obvious reasons, I can’t get full details about how certain classes and structs provided by Unity work. I only can see public members from metadata.
So my question is about Vector2 and Vector3 structures. The most logical way to get magnitude is to store it in a public property with a private set accessor and only recalculate it when a new vector is created or when one of vector’s components changes.
However, Unity documantation here says it’s preffered to use sqrMagnitude instead of magnitude in some cases. As if to improve performance, they are only calculated when called. This makes me think these properties realized in this way:
public float magnitude => Mathf.Sqrt(x * x + y * y + z * z);
public float sqrMagnitude => x * x + y * y + z * z;
So how do these properties actually work?