Topic was automatically imported from the old Question2Answer platform.
Asked By
Robster
Old Version
Published before Godot 3 was released.
Hi all,
I’m stumped, I’ve spent hours on this but have crumbled and am asking.
Why does the following give the error: Invalid call. Nonexistent function 'get_node' in base 'Reference ()'.
It’s on the line: mousePos = get_node("/root/gameLevel/batIndicatorL").get_pos()
func mouseControl(delta):
#let's make the bat, move TO the mouse position indicator at the correct speed
#left player
if bat.PlayerNumber == 1:
var mousePos = Vector2(0,0)
mousePos = get_node("/root/gameLevel/batIndicatorL").get_pos()
bat.move_to(Vector2(70, mousePos.y))
Note1: there really is an item at /root/gameLevel/batIndicatorL. Note2: The function mouseControl(delta) is inside a class. So it’s a method of sorts I guess you’d say? (new to this)
oh I forgot that get_tree() is available under Node.
my mistake.
KinematicBody2D is inherited by Node , so I think it should be fine with your code.
Would make and share a little sample project?
volzhs | 2017-02-08 08:04
Sure can. Much appreciated! It does have my artwork etc though and I’d rather share privately if that’s ok? Is there a way I can share a private link to you? EDIT: Of course I’ll place the solution here when finalised. I just don’t want to share the whole project publicly.
it should be fine if using get_node under extends KinematicBody2D.
I guess you made a custom class extends Reference and trying to use get_node inside that class.
in this case, no matter where script is located.
I think, there should be an reference for SceneTree or root viewport -get_root()- inside your custom class.
I will check further if you send me a link.
volzhs | 2017-02-08 16:30
You have reference of KinematicBody2D instance as var bat
then you can access get_node or get_tree through the bat reference.
Try this code.