Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Strange error related to vectors and UnityEngine-Debug.dll

Discussion in 'Editor & General Support' started by TommiH, Sep 14, 2008.

  1. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    I'm getting this bizarre error:

    error CS0121: The call is ambiguous between the following methods or properties: `UnityEngine.Vector3.operator --(UnityEngine.Vector3, UnityEngine.Vector3)' and `UnityEngine.Vector2.operator --(UnityEngine.Vector2, UnityEngine.Vector2)'
    /Applications/Unity/Unity.app/Contents/Frameworks/UnityEngine-Debug.dll (Location of the symbol related to previous error)

    The annoying thing is, it doesn't tell me what part of my code is causing the error. The link to UnityEngine-Debug.dll doesn't tell me much..

    Thanks for any help.
     
  2. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Can you reproduce the errors in a new project? Would give an idea of what we're dealing with.
     
  3. TommiH

    TommiH

    Joined:
    Jan 14, 2008
    Posts:
    253
    Well, actually I managed to solve it by trial and error. I was adding a Vector3 instance to a Vector2 instance, using the + operator.
     
  4. AngryAnt

    AngryAnt

    Keyboard Operator Moderator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Ah. The error message could be done more nicely though.
     
  5. SARWAN

    SARWAN

    Joined:
    Oct 23, 2012
    Posts:
    11
    I am also getting the same error. How to solve this?

    error CS0121: The call is ambiguous between the following methods or properties: `UnityEngine.Vector2.operator -(UnityEngine.Vector2, UnityEngine.Vector2)' and `UnityEngine.Vector3.operator -(UnityEngine.Vector3, UnityEngine.Vector3)'

    My code part is:
    if(Input.GetMouseButton(0))
    {
    if(prevMousePos.x == 0 prevMousePos.y == 0)
    {
    prevMousePos = Input.mousePosition;
    }
    Vector2 touchDeltaPosition = new Vector2(Input.mousePosition - prevMousePos);
    prevMousePos = Input.mousePosition;
    }
     
  6. David_29

    David_29

    Joined:
    Jan 22, 2014
    Posts:
    12
    Try casting. It may resolve the problem.

    For example, let's say this is the code (in C#):

    private Vector2 lastPos
    private bool swiping


    void Update() {
    if(Input.touchCount == 0) {
    if(Input.mousePosition.sqrMagnitude != 0) {
    if(!swiping) {
    swiping = true;
    lastPos = Input.mousePosition; // --> mousePosition is Vector3 and still acceptable.
    return;
    } else {
    Vector2 direction = (Vector2) Input.mousePosition - lastPos; // --> I simply add a cast onto the mousePosition to resolve it.
    }
    } else {
    swiping = false;
    }
    }
    }
     
  7. David_29

    David_29

    Joined:
    Jan 22, 2014
    Posts:
    12
    Try casting. It may resolve the problem.

    For example, let's say this is the code (in C#):

    private Vector2 lastPos
    private bool swiping

    void Update() {
    if(Input.touchCount == 0) {
    if(Input.mousePosition.sqrMagnitude != 0) {
    if(!swiping) {
    swiping = true;
    lastPos = Input.mousePosition; // --> mousePosition is Vector3 and still acceptable.
    return;
    } else {
    Vector2 direction = (Vector2) Input.mousePosition - lastPos; // --> I simply add a cast onto the mousePosition to resolve it.
    }
    } else {
    swiping = false;
    }
    }
    }