StartPath callback not working

I’m trying to get RandomPath working, currently it’s supposed to make a random path, and when it reaches the end of said path it throws a call back to the AI to seek further instructions:

`	public void RandomMovement(GameObject npc){
		int maximumPathfindingRange = 15;
		RandomPath path = RandomPath.Construct (transform.position, maximumPathfindingRange);
		Seeker seeker = GetComponent<Seeker>();
		seeker.StartPath (path, PathCompleted(npc));
	}

	public void PathCompleted(GameObject npc){
		npc.GetComponent<AIGuard> ().SetTransition (Transition.Think);
	}`

However, it throws an error ‘No overload for method StartPath takes 2 arguments’. I swear I have the syntax right, does StartPath simply not like callbacks?

Secondarily, and I know this is a fairly dense question, once the seeker has calculated a path, how do I actually feed it to my AIPath? Do I need to write a function to find and feed AIPath with waypoints one at a time?

Hi

The StartPath function takes a callback, you are trying to pass it the result of a function call, which in this case is ‘void’. It should be like this:

`seeker.StartPath (path, PathCompleted); // Note no parentheses

public void PathCompleted ( Path path ) {
// Result is in the Path variable
}`

See http://arongranberg.com/astar/docs/getstarted.php

The way you should approach it is by inheriting from the AIPath class and overriding the SearchPath function.
`
public class MyAI : AIPath {
/** Requests a path to the target */
public override void SearchPath () {
// Needed to make sure it doesn’t starts searching for paths again instantly
lastRepath = Time.time;
canSearchAgain = false;

	int maximumPathfindingRange = 15000;
	RandomPath path = RandomPath.Construct (transform.position, maximumPathfindingRange);
	seeker.StartPath (path);
}

   public override void OnTargetReached () {
        // Do stuff
   }

}

`

There is just one thing you have to do. By mistake I have made the lastRepath variable private, it shouldn’t be, so you need to open the AIPath.cs script and change it from private to protected, otherwise your script will not be able to access it.

This is detailed, comprehensive, extremely thorough, and solves every single problem I was having, thank you very much for your time! I really appreciate the support :slight_smile:

Thanks.

I wish you the best of luck with your game!

PS: If you have the time, would you consider voting on the A* Pathfinding Project Pro on the Asset Store and/or writing a review?

Sure thing, consider it already done ^^