Nonexistent function error, but function exists

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StrikerMF4

Hi!, I am making an editor plugin, but I cannot access the functions of a custom node (that extends Node3D)

In the next code:

print(entity.has_method("get_connections"))
entity.get_connections()

the first line displays true
but the next line displays the error Invalid call. Nonexistent function 'get_connections' in base 'Node3D (Entity3D)'.

I also tried with (entity as Entity3D).get_connections() with the same result

Am I missing something?

So this get_connections() method is something you’ve added to your extended node? Because a Node3D doesn’t have a get_connections() method.

If that’s the case, maybe post the relevant code that extends Node3D?

BTW, a Signal does have an in-built get_connections() method…

jgodfrey | 2023-03-05 20:22

Yes, is a method I’ve in the Entity3D script

This is the code of Entity3D:

extends Node3D
class_name Entity3D

func get_connections():
	var connections = []
	for child in get_children():
		if child.get_script() is PuzzleInput and child.exposed:
			connections.append({ "input": child as PuzzleInput, "connections": child.get_connections()})

StrikerMF4 | 2023-03-05 20:35

A quick, simple test seems to indicate this works as intended. First, an Entity3D script (a stripped down version of your code above):

extends Node3D
class_name Entity3D

func get_connections():
	print("called get_connections")

Then, from another node’s script…

func _ready():
	var entity = Entity3D.new()
	print(entity.has_method("get_connections"))
	entity.get_connections()

Output:

true
called get_connections

How are you getting your entity reference in the code you posted above?

jgodfrey | 2023-03-06 00:57