Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

utmath.Vector3 vs ut.Math.Vector3?

Discussion in 'Project Tiny' started by Berzee, Dec 10, 2018.

  1. Berzee

    Berzee

    Joined:
    Sep 3, 2013
    Posts:
    11
    I created a component with a Vector3 field on it and noticed that it was incompatible with another Vector3 from, for example, Core2D.TransformLocalPosition.position.

    Turns out there are two Vector3 classes with subtly different package names, "ut.Math" vs "utmath", though that's not immediately obvious from the displayed error:

    TypeScriptError: Argument of type 'ut.Math.Vector3' is not assignable to parameter of type 'Vector3'.
    Type 'Vector3' is missing the following properties from type 'Vector3': set, setScalar, setX, setY, and 61 more.


    So if I want to do things in a System like check the length of the Vector3 or use the vector math functions, I have to convert to the "other" Vector3 at the beginning of the script and then convert back at the end to save the results in the component.

    This made me curious if there is a reason for only offering the basic version on user-created components? Or did I miss a way of choosing between the two for my component? I don't know anything about ECS, so maybe it's to do with the components only storing data and not behaviour...but I see the core components do include the other, more full-featured type of Vectors.

    I don't say it should be different, just wondering why it is the way it is. =) At the very least, the confusion between the duplicate class names or almost-identical package names (utmath and ut.Math??) might be worth considering. ¯\_(ツ)_/¯
     
  2. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    In ECS, which Tiny is based on, you use float3 not Vector3
     
  3. Berzee

    Berzee

    Joined:
    Sep 3, 2013
    Posts:
    11
    Does float3 come with the ability to do simple math operations on it, or do you have to convert to Vector3 in each System?

    (I do think naming it float3 makes it more clear that it's just a collection of 3 numbers, and not an actual mathematical vector)
     
  4. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    I ran across this issue as well . . . . I set a Vector3 as a property on a component but it would not recognize it in TypeScript. So I took the property and converted it into a Vector3 on the flyin the System

    Here player is a Component with a Vector3 called currentVelocity

    Code (JavaScript):
    1. let vel = new Vector3(player.currentVelocity.x,player.currentVelocity.y, player.currentVelocity.z) ;
    As for Math operations Tiny has its own set of operations
     
  5. v_vuk

    v_vuk

    Unity Technologies

    Joined:
    Jul 11, 2017
    Posts:
    36
    A fix for the original issue is coming in the next hotfix; they are actually the same type, just TypeScript didn't know that they are. The overall math situation is not great -- math and vector math in JS/TS in general is not great, and C# will help a ton in this area.
     
    Berzee and vincismurf like this.