AI moves to corner of NavMesh

Video of Issue

I’m having an issue where, when the AI’s target is set to one of the 8 seats in a restaurant, they just move towards one of the corners of the navmesh, as you can see in the video. The weird thing is, when I manually place the same object into the target variable, it does go to the right spot. Does anyone know why this might be happening?

Hi

It looks like you’ve made changes to the AIDestinationSetter. To help you debug any further, I’d need to see the code that you changed.

namespace Pathfinding {
///


/// Sets the destination of an AI to the position of a specified object.
/// This component should be attached to a GameObject together with a movement script such as AIPath, RichAI or AILerp.
/// This component will then make the AI move towards the set on this component.
///
/// See:
///
/// [Open online documentation to see images]
///

[UniqueComponent(tag = “ai.destination”)]
[HelpURL(“A* Pathfinding Project”)]
public class AIDestinationSetter : VersionedMonoBehaviour
{
/// The object that the AI should move to
public Transform target;
IAstarAI ai;

	[SerializeField]
	List<GameObject> targets = new List<GameObject>();

	private static int seatIndex = 0;

	private void Start()
	{
		target = targets[0].transform;
    }

	void OnEnable()
	{
		ai = GetComponent<IAstarAI>();
		// Update the destination right before searching for a path as well.
		// This is enough in theory, but this script will also update the destination every
		// frame as the destination is used for debugging and may be used for other things by other
		// scripts as well. So it makes sense that it is up to date every frame.
		if (ai != null) ai.onSearchPath += Update;
	}

	void OnDisable()
	{
		if (ai != null) ai.onSearchPath -= Update;
	}

	/// <summary>Updates the AI's destination every frame</summary>
	void Update()
	{
		if (target != null && ai != null) ai.destination = target.position;
	}

	private void setTarget()
	{
		target = targets[seatIndex].transform;
	}

	public void changeTarget()
	{
		if (seatIndex < 8)
		{
			seatIndex++;
			setTarget();
			Invoke("leave", 10f);
		}
		else
		{
			seatIndex = 1;
			setTarget();
			Invoke("leave", 10f);
		}
	}

	public void leave()
	{
		target = targets[9].transform;
		Invoke("destroyCustomer", 8f);
	}

	private void destroyCustomer()
	{
		Destroy(gameObject);
	}

}

}

What we’re trying to do is make a system where customers (the ai) will walk in to the restaurant and wait at the counter to give their order. Then, once they get their order, they go to one of the 8 tables in the restaurant, sit there for a little bit, and then leave. The idea for what we have right now is that they would all have the same target at the beginning (index 0 of the list) and then once they get their order, the changeTarget method would be called which would give them a new target that would be different from the previous customer, that way two customers aren’t sitting at the same table.