OnPathComplete additional parameters

I need to have a callback function that accepts more than just Path p. I’ve tried adding my own callbacks with

seeker.pathCallback -= OnPathComplete;
seeker.pathCallback += CustomPathCallback;

seeker.StartPath(transform.position, walkTarget, CustomPathCallback(int x = 5);

public void CustomPathCallback(int x, Path p)
{

}

But I get an error saying “No overload matches OnPathDelegate”. How could I make a custom callback that accepts more than just the parameter ‘p’ (it still needs to accept ‘p’ so I can do post-modifications to the path.

Thanks

Hi

You can do something this by wrapping it in another callback. So it first calls a callback with a single Path parameter, which in turn calls your custom callback.

seeker.StartPath(transform.position, walkTarget, (Path p) => CustomPathCallback(5, path));

thank you for your quick response. Your program is great btw really appreciate it.

I’m not a C# expert, so if I understand you correctly, the first callback called I do not have to specify, its an anonymous function. The ‘Path p’ variable will then be passed from there to CustomPathCallback, which I can make a definition for. How does the anonymous function know which parameter to pass ‘Path p’ to CustomPathCallback? I mean, if i have even more parameters, which one should be ‘path’ in CustomPathCallback?

Thanks again

Ah I think on further research, If i want to work with the unprocessed ‘p’ variable in the custom callback in much the same way as OnPathComplete before assigning ‘p’ to ‘path’, the parameter should be ‘p’ and not ‘path’ in the lambda expression to work with the ‘p’ being passed to it. If that makes sense. For example, something like this

Path path = null;
seeker.StartPath(transform.position, walkTarget, (Path p) => CustomPathCallback(5, p));

CustomPathCallback(int x, Path p) {
…do stuff with p
path = p;
}

Hi

You can name your variables whatever you want. You can change ‘p’ to ‘blah’ if you feel like it. They are just identifiers. Only the order of them really matters.