I need help figuring out why my signals aren't working

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

So I have used signals to connect child node instances to the parent before but for some reason it is not working this time and as far as I can see I’m doing exactly what I did before.
Here’s some code snippets of my current issue(edited for simplicity):
Child node:

signal button_selected

func button_clicked(num):
print(“signal sent from button”)

Parent node:

func spawn_buttons(num,pos):
for i in range(num):
var b = button.instance()
b.position = pos[i]
i = i + 1

func _on_button_select():
print(“signal received”)

The “signal sent from button” is printing in my console but the “signal received” is not so for some reason the signal is not being received by my parent node? I have used this exact method before when sending signals from child instances and it worked perfectly. If anyone can spot what I’m doing wrong it’d be hugely helpful. I’m new to godot and it feels like I’m hitting a wall with this issue

Oh, please use code blocks, it’s kind of hard to read like this, especially when markup turns underscores into italics…
From the code you posted, I can’t tell exactly what’s causing your issue, but as a side note you probably shouldn’t have i = i + 1 inside of the for loop.

CardboardComputers | 2022-03-14 03:06

Sorry about the formatting I’ve never used this site and don’t know how to use code blocks . I’m aware that the i = i + 1 isn’t ideal but it does work. My issue is more concerning the signal stuff, that for loop is just to spawn instances of the child node

BungeryChubbins | 2022-03-14 09:07


or try

ramazan | 2022-03-14 12:10

Adding four extra spaces at the beginning of each line turns it into a code block; the easiest way is to just indent it in a code editor before copying it over.

Maybe I’m missing something, but it seems to me like everything in the code you posted should allow the signal to be received; maybe you edited out the issue when you were simplifying the code for posting? The only thing really out of place is the i = i + 1. You don’t need that since for i in range(n) already increments i after every iteration, but that shouldn’t affect the signals at all.

CardboardComputers | 2022-03-14 13:41

:bust_in_silhouette: Reply From: Gamespot

name of the signal in child node and in connect method are different

name of signal in child node : button_selected
name of signal in connect method in parent node : buttonselected

I have the names identical (they were before too I just messed up formatting my question). Do you have any other suggestions as to what could be causing the signal to not be received?

BungeryChubbins | 2022-03-17 11:11

share the screenshot of its scene tree and script of both

Gamespot | 2022-03-17 13:14

Here's a screenshot of the code, I've circled the parts relevant to my query

BungeryChubbins | 2022-03-18 17:18

Also worth mentioning that I keep getting errors saying the signal is nonexistent? I’m at a complete loss here I’ve been trying this for days to no avail

BungeryChubbins | 2022-03-18 18:03

Looking at this picture, I think I might know what is happening. The signal is within your button2.tscn(script whatever that is callled can’t tell) and the current scene cannot access it properly, hence why it can’t find the signal.

For a test or possible solution, create a global singleton class that is for signals only, lets call it mysignals.gd, you can set this in the project settings under autoload by adding it and giving it a node name such as MySignals. If you do this you can call these signals from any class or anywhere. With this you would have remove how you currently connect in the classes, and hopefully I am explaining this simply enough. Warning might have to correct tabs with the code I am writing below.

in MySignals.gd 

signal button2_selected()
#you can pass variables in here as well if you want example below 
#signal button2_selected(passwhatever), Note this will have to accounted for in the method that receives the signal, for example 
# _on_button_on(passwhatever): 

In minigame1.gd 

func _ready():
      #this will connect this class minigame1.gd to the button2_selected signal, so any time that global class signal used goes off it will come to the function declared here. 
      MySignals.connect("button2_selected", self, "_on_button_on")

In the button2.tscn(script file name, not sure whatever it is).gd
#in the click button function on this button(if you are using a standard godot class button), this can be easily created if you are using standard godot button class buttons)
In the right side of the editor(by defualt) click the node and link a pressed() function to a signal function. If you are not sure how to do this lookup buttons in godot tutorials, its pretty simple.
for example pressed() ->signal _on_button_pressed()

   func _on_button_pressed()  -> void: 
   #when this button is pressed, it will pass this signal to anything connected to it. 

This should be a simple way of getting it working, without seeing how everything is done, I wouldn’t be able to help you with the way you are trying to do it. Note doing this global way of doing signals will give warnings that your signal is never emitted, but obviously if it works then it is.

Hope this leads you in the right direction.

r.bailey | 2022-03-18 18:51

The global singleton method worked! Thank you so so much. You’re a legend and a half r.bailey :slight_smile:

BungeryChubbins | 2022-03-19 20:20

:bust_in_silhouette: Reply From: r.bailey

Looking at this code the issue is that you need the names of the signals you are using be the same in emitting and connecting to.

#name of signal needs to match in emitsignal and connect functions. 
signal button_selected
func buttonclicked(num):
print("signal sent from button")

#this is where the error was on connecting the correct signal name below. 

I have the names identical (they were before too i just messed up formatting my question). Do you have any other suggestions as to what could be causing the signal to not be received?

BungeryChubbins | 2022-03-17 11:11