Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Squatnet |
I’m having a strange bug with instanced buttons.
I have a main scene that looks like
Control
- Control
- - HboxContainer
- Control
- - HboxContainer
- Control
- - HboxContainer
and i instance some buttons into each of the HBoxContainers
each of the buttons when pressed, should turn pressed = false
for its siblings
for i in get_parent().get_children():
i.pressed = false
For some strange reason, the buttons inside the other controls also turn off which is unexpected.
Control.tscn
Control (Main)
- Control (BtnSet1)
- - HboxContainer (HBoxContainer)
- - - (Buttons here)
- Control (BtnSet2)
- - HboxContainer (HBoxContainer)
- - - (Buttons here)
- Control (BtnSet3)
- - HboxContainer (HBoxContainer)
- - - (Buttons here)
Control.gd
extends Control
var set1Opts = [1,2,3,4,5,6]
var set2Opts = [1,2,3,4]
var set3Opts = [1,2,3,4,5,6,7,8,9,10]
# Called when the node enters the scene tree for the first time.
func _ready():
var packedBtn = load("res://Button.tscn")
for i in set1Opts:
var insBtn = packedBtn.instance()
insBtn.setup(str(i),"set1")
$BtnSet1/HBoxContainer.add_child(insBtn)
for i in set2Opts:
var insBtn = packedBtn.instance()
insBtn.setup(str(i),"set2")
$BtnSet2/HBoxContainer.add_child(insBtn)
for i in set3Opts:
var insBtn = packedBtn.instance()
insBtn.setup(str(i),"set3")
$BtnSet3/HBoxContainer.add_child(insBtn)
Button.tscn
Just a button, toggle mode on
Button.gd
extends Button
var type
# Called when the node enters the scene tree for the first time.
func _ready():
pass
func setup(name, butType):
text = name
type = butType
func _on_Button_toggled(button_pressed):
print(get_parent().get_parent().name)
print(get_parent().get_children())
for i in get_parent().get_children():
i.pressed = false
print(i.text)
Whats even stranger is that it only prints to console only the siblings as expected but does in fact turn all buttons off even those ones in different nodes
minimal reproduction project (made with 3.1.1 but occurs in 3.1 also)
https://github.com/Squatnet/GodotInstancingBugMinReproProj
Have since tried
- Change toggle mode setting on button
- swapping pressed() with toggled()
which has made no difference
Squatnet | 2019-06-20 19:46