Search Unity

float2 float3 implicit conversion

Discussion in 'Entity Component System' started by JooleanLogic, Jun 14, 2019.

  1. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Is there a reason for no implicit conversion operators between float2 and float3 like there is for Vector2 and Vector3?

    I notice in float2.gen.cs there's a bunch of hidden conversion properties like 'float3 xxx{}'.
    There's a downcast float3.xy to go from float3 to float2 but no upcast that I can see.
    How about a float2.xy0?
     
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    The implicit conversion operators for Vector2/Vector3 were one of the worst ideas ever as there is simply no single correct way to do it as it depends on the use case and errors were well hidden.

    There is
    Code (CSharp):
    1. new float3(xy, z).
     
    JooleanLogic likes this.
  3. JooleanLogic

    JooleanLogic

    Joined:
    Mar 1, 2018
    Posts:
    447
    Ah cool, thanks Julian. How on earth did I not notice that constructor before. :(
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Yep, please never add implicit float23 conversions.

    Vector23 implicit conversion has caused me more bugs than anything else when developing by a an order of magnitude.

    I do totally support methods or properties or whatever (I use extension methods myself) to easily convert to different formats.