Godot Version
Godot 4.3
Question
I am using Node.get_children()
to to get all of a Nodes children. But the function returns Nodes (as Array[Node]). Some of these Nodes are Buttons. These are the ones I actually want, so i wrote a function that iterates through the returned Array[Node] and should return a filled Array[ Button].
The Problem is, I have no way of recognising whether one of the Nodes is a Button or not.
Here’s my code:
var children = button_parent.get_children()
var buttons = get_btn_from_nodes(children)
func get_btn_from_nodes(nodes):
var res : Array[Button]
for node in nodes:
#this is where the magic should happen
#if :
res.append(node)
return res
I am stuck and please need help, how can i access the Button from script?
The fact i havent found anything similar means its either super basic or just not possible, in which case it would be nice if you could point me in the right direction.
Solution:
i have to apologize, I somehow expected that TextureButton
inherits from Button
and could therefore be found with If child in Button:
which, as i now know, was false. Button
and TextureButton
both inherit from BaseButton
.
Thank your for your help