A* Pathfinding Project

It get stuck when randomly walk


#1

Hi all, I’m testing free version. Here is my code:

public void ActionStart()
{
    StopAllCoroutines();
    StartCoroutine(SetRandomDestination());
}

IEnumerator SetRandomDestination()
{
    for (int i = 0; i < 30; i++)
    {
        // select random point in my area..
        targetDestination = new Vector3(Random.Range(-30, 30), 1,Random.Range(-30, 30));

        GraphNode node1 = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
        GraphNode node2 = AstarPath.active.GetNearest(targetDestination, NNConstraint.Default).node;

        if (PathUtilities.IsPathPossible(node1, node2))
        {
            seeker.StartPath(transform.position, targetDestination, OnPathComplete);
            break;
        }
        if (i == 29)
        {
            // recall this code at another script.. "ActionStart()"
            break;
        }
        yield return null;
    }
}

public void OnPathComplete(Path p)
{
    if (p.error)
    {
         // recall this code at another script.. "ActionStart()"
    }
    else
    {
        ai.destination = targetDestination;
        StartCoroutine(PathFinishControl());       
    }
}

IEnumerator PathFinishControl()
{
    yield return new WaitForSeconds(.5f); // if I delete this line then ai calculate path two times.. :(

    while (!ai.reachedEndOfPath)
    {
        yield return new WaitForSeconds(.5f);
    }

    // recall this code at another script.. for different destination.
}

My object has Smooth Modifier.
Problem:
My object random walking. Some times everyting fine but some times object stop and send this log messages:
“Path Completed : Computation Time 0.00 ms Searched Nodes 0 Path Length 1
Path Number 34 (unique id)
Path Completed : Computation Time 0.00 ms Searched Nodes 0 Path Length 1
Path Number 35 (unique id)
… (repedeatly…)”

(Sometimes it gets stuck in the green area. not only edge…)
What am I doing wrong? Thanks…