Ambiguous reference between two references

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()
{

}
}

1 Like

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:

using Vector3 = UnityEngine.Vector3;
18 Likes

Thank you so much! That solved my problem! You are a savior and a scholar!

3 Likes

thanks alot. i was using both
using system.Numeric;
using UnityEngine;

now i am only
using UnityEngine;

Thank you so much dude i just started learning unity and this happened to me!