Unity.Mathematics missing implicit conversion for int2/3/4 to/from Vector2/3/4Int

Hi,

I’m looking at the source Unity.Mathematics/src/Unity.Mathematics/math_unity_conversion.cs at master · Unity-Technologies/Unity.Mathematics · GitHub
and I’m wondering why there are no implicit conversion operators for int2 to/from Vector2Int, respectively int3 to/from Vector3Int and int4 to/from Vector4Int.

This looks to me like a major oversight which could be easily solved.

As a result of this oversight, using EditorGUILayout.Vector2IntField with int2 requires explicit creation of a Vecto2Int, which makes the resulting code way harder to read than it ought to be.

So, question: was this oversight really just an oversight, or done on purpose? If it’s the latter, what’s the reason?
Also, would you take a pull request on the GitHub repo to add the missing operators?

Cheers.

1 Like

Is it possible to make an extension method to do the conversion in a more readable manner?

public static Vector2Int AsVector2Int(this int2 i2) => new Vector2Int(i2.x, i2.y);

Would be handy to have conversion operators though.

Extension methods don’t beat having direct cast operators, though. And those cast operators have to be implemented inside the Assembly that defines the class.

+1