Signal errors by preload a scene

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

Hello, I have a problem when I say in my script

var object = preload ("res: //scene/object.tscn") .instance ()

and the object is duplicated.
then everything loads perfectly, but my scene contains a signal, to be precise a button signal.
If I press the button then the output shows an error:

E 0: 00: 04.882 emit_signal: Error calling method from signal 'pressed': 'Node2D (tree.gd) :: _ on_Button_pressed ()': Method not found ..
   <C ++ source code> core / object.cpp: 1260 @ emit_signal ()

this cannot then be carried out.
Does anyone know what I mean and what I can do?

Thanks in advance

Does the method exist on the object you are running .instance() if not, you may have to make the signal connection in code. For example, if you have a main scene instancing enemies and those enemies have signals that need to call the main scene’s methods, you can connect the signals to the main scene when it creates the enemies. Check out connecting signals in code.

Tom Mertz | 2020-12-13 03:15

:bust_in_silhouette: Reply From: demwilson

The function referenced in the .tscn file is not defined in the .gd file.

What do you mean by:

“… the object is duplicated.”

It would be fastest if you can you share the two files here so we can be more helpful.

:bust_in_silhouette: Reply From: Ertain

In the signal connection for the button (in the editor), is the function name correctly written out? Note how the error prints out the function name _ on_Button_pressed ().