Scene instantiated in code connects signals twice

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

I have a world scene that routinely creates instances of another, smaller scene called Segment. Segment has a lot of internal stuff going on with many smaller parts that communicate with each other through signals. When I tested the logic of the world scene out with a less complex scene to instantiate, everything went fine. But when I swapped that less complex scene out with the actual Segment scene that I want to use, things started going awry.

Every time I instantiate one, I get a big frame rate drop, and then Godot prints the following error to the console:

connect: Signal 'my_signal' is already connected to given method 'my_method' in that object

It prints this for every single signal I have connected within Segment, which is like 10 (hence the framerate drop).

I do not connect any signals through code within Segment – every one is connected through the editor.

Here’s my code for instantiating a segment, which is in my World.gd script:

        guy = Segment.instance()
		guy.position.y = offset
		guy.initialize()
		call_deferred("add_child", guy)

where Segment is the name of a variable containing a preloaded PackedScene of my Segment scene.

The weirdest thing to me is that my test scene that I substituted Segment for also has a signal connected between two of its children, but I never get this error when instantiating the test scene. Is this just an issue of having too many signals?

EDIT: After a little more testing, I’ve found that I do not get these errors from the first two times I instantiate Segment, but I do get them for the third time I try to, and every time after that.

:bust_in_silhouette: Reply From: Solid_Turner

My apologies, I should have done more extensive testing, I was pretty tired last night. It turns out that I have a bug that tries to instantiate the same scene several times instead of just once, and that’s where my error is coming from.

Happens to all of us!

timothybrentwood | 2021-05-13 13:19