AIPath bug with TargetReached

/** True if the end of the path has been reached */
public bool TargetReached { get; protected set; }

This doesn’t work if change target.position but a new path hasn’t been calculated yet. This is partly Unity’s fault by letting you change values in the inspector without going through an accessor.

I made the following workaround (I’ll send you the full file by private message if you want it)

/** True if the end of the path has been reached */
private Vector3 lastPathCompleteEndPoint = Vector3.zero;
protected bool targetReached;
public bool TargetReached
{
get
{
if (target == null)
return false;

  	if ((target.position - lastPathCompleteEndPoint).sqrMagnitude > endReachedDistance * endReachedDistance)
  	{
  		// The user requested a new target position that wasn't calculated yet
  		return false;
  	}
  	return targetReached;
  }
  set
  {
  	lastPathCompleteEndPoint = target.position = tr.position;
  	targetReached = true;
  }

}

public float TrySearchPath () {
if (Time.time - lastRepath >= repathRate && canSearchAgain && canSearch && target != null && TargetReached == false) {
SearchPath();
return repathRate;
} else {
float v = repathRate - (Time.time-lastRepath);
return v < 0 ? 0 : v;
}
}

if (distanceToEnd <= endReachedDistance && !targetReached) {
targetReached = true;
OnTargetReached();
}

// Reset some variables
targetReached = false;
lastPathCompleteEndPoint = p.originalEndPoint;