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

Ambiguous reference between two references

Discussion in 'Scripting' started by Zerith, May 8, 2020.

  1. Zerith

    Zerith

    Joined:
    Apr 14, 2020
    Posts:
    6
    Hello! I am getting an error when initializing the Vector 3 targetPosition in the code below.
    This is the error code:
    Here is the error:
    Error CS0104 ‘Vector3’ is an ambiguous reference between ‘System.Numerics.Vector3’ and ‘UnityEngine.Vector3’

    Here is my code:

    using System.Collections;
    using System.Collections.Generic;
    using System.Numerics;
    using UnityEngine;

    public class Enemy : MonoBehaviour
    {
    [SerializeField]
    private Transform[] waypoints;
    private Vector3 targetPosition;
    // Use this for initialization
    void Start()
    {
    targetPosition = waypoints[0].position;
    }
    // Update is called once per frame
    void Update()
    {

    }
    }
     
    daniel_ea likes this.
  2. Ardenian

    Ardenian

    Joined:
    Dec 7, 2016
    Posts:
    313
    Class definitions can have the same name while being in different namespaces. There is a definition for
    Vector3
    in
    System.Numerics
    and there is one in
    UnityEngine
    . Since you use both of these namespaces in this code via using directives, it gets confused what it should use.

    Either remove
    using System.Numerics;
    , which doesn't appear to be used in the code, or add the following line under your using directives:
    Code (CSharp):
    1. using Vector3 = UnityEngine.Vector3;
     
  3. Zerith

    Zerith

    Joined:
    Apr 14, 2020
    Posts:
    6
    Thank you so much! That solved my problem! You are a savior and a scholar!
     
  4. adeelahmed1

    adeelahmed1

    Joined:
    Jul 14, 2020
    Posts:
    1
    thanks alot. i was using both
    using system.Numeric;
    using UnityEngine;

    now i am only
    using UnityEngine;
     
  5. Silent_X

    Silent_X

    Joined:
    Dec 23, 2022
    Posts:
    1
    Thank you so much dude i just started learning unity and this happened to me!