- Home /
Overload for method Not Compatible
I am working on a A* implementation, and I am down to one bug in my code that I can not for the life of me figure out. There error is:
The best overload for the method 'Node.getId(UnityEngine.GameObject)' is not compatible with the argument list '(System.Type)'.
Here are the two scripts:
#pragma strict
import System.Collections.Generic;
class Graph
{
var edges : List.<Edge> = new List.<Edge>();
var nodes : List.<Node> = new List.<Node>();
var pathList : List.<Node> = new List.<Node>();
function Graph(){}
/*================================================================================*/
function AddNode(id : GameObject, removeRenderer : boolean, removeCollider : boolean)
{
var node : Node = new Node(id);
nodes.Add(node);
//remove colliders and mesh renderer
if(removeCollider)
GameObject.Destroy(id.collider);
if(removeRenderer)
GameObject.Destroy(id.renderer);
}
/*================================================================================*/
function AddEdge(fromNode : GameObject, toNode : GameObject)
{
var from : Node = findNode(fromNode);
var to : Node = findNode(toNode);
if(from != null && to != null)
{
var e : Edge = new Edge(from, to);
edges.Add(e);
from.edgelist.Add(e);
}
}
/*================================================================================*/
function findNode( id : GameObject)
{
for(var n : Node in nodes)
{
if(n.getId() == id)
{
return n;
}
}
return null;
}
The issue appears to be in the findNode function. That function references another script pasted below:
#pragma strict
import System.Collections.Generic;
class Node
{
var edgelist : List.<Edge>;
var path : Node = null;
var id : GameObject;
var xPos : float;
var yPos : float;
var zPos : float;
var f : float;
var g : float;
var h : float;
var cameFrom : Node;
function Node(i : GameObject)
{
id = i;
xPos = i.transform.position.x;
yPos = i.transform.position.y;
zPos = i.transform.position.z;
path = null;
}
function getId(id : GameObject)
{
return id;
}
}
I have been beating my head against the wall on this for a while now. Any help you could offer would be greatly appreciated.
Regards, Tony
Just a thought (not a JS expert): you don't seem to be specifying a return type on the getId function. If I remember my JS, that means it'll be expecting void and ins$$anonymous$$d getting a GameObject.
Answer by DaveA · Jan 31, 2013 at 06:08 AM
You call it like this:
if(n.getId() == id) // take NO arguments, returns? (GameObject by looking at definition)
but it's defined like this:
function getId(id : GameObject) // takes a GameObject returns ?
So, either don't have it defined to take any arguments, or pass in a GameObject when calling it.
Your answer

Follow this Question
Related Questions
Unity is recording all info gathered from separate pathfinders into a single array. Why? (JS) 0 Answers
A* nodes in the basic version of unity. 1 Answer
AI Pathfinding Script 4 Answers
Need to change direction of transform? 2 Answers
Path finding using Raycasting inside of Unity(JavaScript) 1 Answer