Invalid call. Nonexistent function 'get_node' in base 'Reference ()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: 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)

:bust_in_silhouette: Reply From: volzhs

get_node() is under Node class.
so, if your class does not extend Node, you can not use it.

try get_tree().get_root().get_node("gameLevel/batIndicatorL")

Thank you for the comment.

As my scene is like so:

- Node2D
-- KinematicBody2D (Script here)
-- more nodes
-- more nodes
-- more nodes

I thought it would inherit the ability to access the features of the Node2D?

If that’s not the case, then at least I know. Thank you.

I just had a go at what you suggested with:

mousePos = get_tree().get_root().get_node("/root/gameLevel/batIndicatorL")

… and received the following error:
Invalid call. Nonexistent function 'get_tree' in base 'Reference ()'.

EDIT: Also with the following I get the same error:

mousePos = get_tree().get_root().get_node("gameLevel/batIndicatorL")

Robster | 2017-02-08 07:16

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.

Robster | 2017-02-08 09:22

ok, send me a link to volzhs at

volzhs | 2017-02-08 14:57

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.

mousePos = bat.get_tree().get_root().get_node("gameLevel/batIndicatorL").get_pos()

volzhs | 2017-02-09 05:47

Thank you. Such a simple mistake. I have bat. in front of all my other functions, but not that one. It’s much appreciated.

Robster | 2017-02-09 06:38