Problem with the initialization of StartPath

Hey there,

first of all, fantastic project!

I have a problem to initialize the Seeker.StartPath method inside a custom script. I tried to adapt the tutorial, but when is Setup the StartPath method with the callback funktion it throws an error (can’t convert the custom OnPathComplete funktion into an OnPathDelegate).

I already tried several thinks, i.e.: Set up a new script, cast the OnPathComplete inside the script to a delegate but nothing seems to work.

I think the problem could be an incorrect initalization of the project.
Does anyone have an ideas how to solve that issue?

Thank you in advace

Hi

I think your OnPathComplete method takes the wrong parameters.

The OnPathComplete method inside the custom class just takes the Path p as parameter and has a void as return type.

Perhaps you have another class called Path in your project?

unfortunatly no. I also checked the Path. It refers to the Pathfinding.Path class

Would you mind posting your code?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;

public class EnemyAI : MonoBehaviour
{
    public Transform target;
    public float speed = 200f;
    public float nextWaypointDistance = 3f;

    Path path;
    int currentWaypoint = 0;
    bool reachedEndOfPath = false;

    Seeker seeker;
    Rigidbody2D rb;
    // Start is called before the first frame update
    void Start()
    {
        seeker = GetComponent<Seeker>();
        rb = GetComponent<Rigidbody2D>();

        seeker.StartPath(rb.position, target.position, OnPathComplete);
    }
    void OnPathComplete(Path p)
    {
        if (!p.error)
        {
            path = p;
            currentWaypoint = 0;
        }
    }
}

The error which is shown is (roughly translated): Argument “3”: convertion of “Methodgroup/Delegate” to “OnPathDelegate” is not possible.
The errorcode is CS1503, maybe thats more helpfull then my translation.

Hmmm… that’s weird… That code looks perfectly correct from what I can see.

Everything that I read about CS1503 points to your Path class being a different one than the pathfinding Path class. Try changing Path to Pathfinding.Path.

Ok, I think i found the problem.

The Pathfinding project wasn’t included properly to my project.
I tried to avoid that conflict with adding the Seeker.cs and the Path.cs data to the current object.
After including the whole project the error dissapeared.

Thank you for your help.

1 Like