I find out Astar still use the old path information by the below code:
void DrawRobotMoveLine()
{
walkLine.enabled = true;
walkLine.startColor = Color.green;
walkLine.endColor = Color.green;
selectRBCursor.gameObject.SetActive(true);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit) && hit.transform.CompareTag(Data.TagTerrain))
{
currentSelectedRobotSeeker.StartPath(currentSelectedRobot.position, hit.transform.position, OnPathComplete);
}
// StartPath() cause the robot moving, but it should not
void OnPathComplete(Pathfinding.Path p)
{
currentSelectedRobotAStar.canMove = false;
// Bug here, Astar on object still use old path even after StartPath called
Debug.Log(Time.time + " " + currentSelectedRobotAStar.remainingDistance + " " + hit.transform.name);
if (TileManagement.MoveStepCheck(currentSelectedRobotAStar.remainingDistance, currentSelectedRobotAI.MaxMoveStep))
{
currentRobotDestination = hit.transform.position;
// shift up, so not overlap with map
walkLine.SetPosition(0, currentSelectedRobot.position + 0.2f * Vector3.up);
walkLine.SetPosition(1, currentRobotDestination + 0.2f * Vector3.up);
selectRBCursor.position = currentRobotDestination + 0.2f * Vector3.up;
}
}
}