![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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):
emit_signal(“button_selected”)
print(“signal sent from button”)
Parent node:
func spawn_buttons(num,pos):
for i in range(num):
var b = button.instance()
button_container.add_child(b)
b.connect(“button_selected”,self,“_on_button_select”)
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
this
b.connect(“buttonselected”,self,“onbutton_select”)
or try
b.onbutton_select()
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