0 votes

Hi everyone !

I have been trying to deal with an a* path finding script based on a grid that I found on this video, the script was originally made on a Spatial node and I tried to translate it on 2D Node, but after 2 hours of debugging I've been stuck for a while with this error :

Invalid call. Nonexistent function 'begin' in base 'Node2D (drawPath.gd)

This error call me back to the line marked with an # :

func drawPath(path):
    var d = get_node("drawPath")
    d.clear() #
    d.begin(Mesh.PRIMITIVE_LINE_STRIP, null)
    for p in path:
        d.add_vertex(Vector3(grid[p].center.x*cell_size,0,grid[p].center.z*cell_size))
    d.end()

I did some research on my own and I think it's mainly because it tries to treat the get_node as a common object.

The draw_path.gd script that is called is in the same directory and attached to a children Node2D.

If you want to have more precision please feel free to ask,

PS : The original code was made in a Godot 2.2 engine or older, it's maybe a compatibility problem I guess ?

asked Jun 11 in Engine by 5hoT0 (12 points)

1 Answer

0 votes

It looks like the code you tried to use was using an ImmediateGeometry node (called "drawPath"), which is how we draw 3D lines from code.

But now your code is 2D and you changed ImmediateGeometry to be a Node2D I guess, so that whole thing with begin, Mesh.PRIMITIVE_LINE_STRIP etc is not going to work there.

Drawing things in 2D works differently, you can do it in several ways:

  • Using the _draw callback, from which you can use functions like draw_line etc

  • Using a Line2D node, which will draw a line based on a list of supplied points

answered Jun 11 by Zylann (13,491 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.