Get_closest_point not working with astar2d

Godot version, v4.2.2.stable.official [15073afe3]

I’m aiming to use the the get_closest_point function and it is returning this error:
Invalid call. Nonexistent function ‘get_closest_point’ in base ‘Callable’.
I’ve checked the documentation and I couldn’t find a solution- here’s a link:AStar2D — Godot Engine (stable) documentation in English
The graph variable is defined as an astar2d in the ready function
func createPoint(cell):
var dot= DOT.instantiate()

dot.position = tileMap.map_to_local(Vector2(cell[0],cell[1]-1)) 
var pos= dot.position
if graph.get_point_position(graph.get_closest_point(pos))==pos:
    return
add_child(dot)
graph.add_point(graph.get_available_point_id(),pos)

Thanks in advance

My quick glance guess is that it looks like it’s going to be a problem with the assignment of graph, since the code seems to think it’s a Callable, not an AStar2D.

Did you perhaps write something like:

var graph = AStar2D.new # Sets graph to be the function 'new' on AStar2D

(i.e. without the brackets) instead of

var graph = AStar2D.new() # Creates a new AStar2D

Thanks, this worked

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.