hi there i have already tried almost everything i can to sort out the issue im having but it still keeps happening i keep getting this error : Failed to create agent because it is not close enough to the NavMesh UnityEngine.Object:Instantiate(Spector) the partof the script it keeps refuring to below; Code (CSharp): void Spector() { SpectorInstance = Instantiate(SpectorPrefab) /*as Spector*/; SpectorInstance.SetLocation(mazeInstance.GetCell(mazeInstance.RandomCoordinates)); } the code for the Sprctor(nevmash agent) Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI; public class Spector : MonoBehaviour { [SerializeField] public GameObject _destination; NavMeshAgent _navMeshagent; private MazeCell currentCell; private MazeDirection currentDirection; public void SetLocation(MazeCell cell) { if (currentCell != null) { currentCell.OnPlayerExited(); } currentCell = cell; transform.localPosition = cell.transform.localPosition; currentCell.OnPlayerEntered(); } // Use this for initialization public void Start() { _navMeshagent = this.GetComponent<NavMeshAgent>(); _destination = GameObject.FindWithTag("Player"); if (_navMeshagent == null) { Debug.LogError("Nav Mesh Agent component not found attached to " + gameObject.name); } else { SetDestination(); } } private void SetDestination() { NavMeshHit closestHit; if (NavMesh.SamplePosition(transform.position, out closestHit, 100f, NavMesh.AllAreas)) { transform.position = closestHit.position; } if (Time.time > .1f) { GetComponent<NavMeshAgent>().enabled = true; } if (_destination != null) { Vector3 targetVector = _destination.transform.position; _navMeshagent.SetDestination(targetVector); } } } any help would be great and thanks in advance
Can you visualize where are you trying to put your agent? Add this code between lines 52 and 53: Code (CSharp): GameObject.CreatePrimitive(PrimitiveType.Sphere).transform.position = closestHit.position; This will create a sphere and place it where you trying to place your agent. After adding the code, open navigation tab to make navmesh visible and then you'll see where it really is. This is how I was debugging such errors.
Can your Spector move over the area where spere is created? Have your tried using _navMeshAgent.Warp(position) instead of setting transform.position value directly?
I've rewrote the script many different ways added extra bits and removed some bits but still throws the same error