I have a script that takes all children of a container node and arranges them in a circle at a given radius from center. This functions correctly.
The problem I have is that the parent scene has multiple children that can be used, and in the inherited scenes I want to choose which of these children nodes to show. To that end, I have tried setting up a for loop which checks if the child has been set to visible in the inspector, and if NOT, it is removed from the array of children generated at the beginning of the method.
Here's the code:
var buttons = get_children()
for button in buttons:
if buttons.size() == 0:
The odd thing is that it doesn't get the correct visible value for every child. Some return as visible when they are not visible, and vice versa. In game, the correct children show, but the calculation that follows the above code (and arranges the children in a circle) is based on the array size, which is incorrect after running through the for loop.
Here's a cap from the editor:
From that image, you can see that Button 6, 8 and 10 are set to visible:false in the inspector (and they are not visible in game, as expected), but they pass the visible check in the for loop. All the buttons are the same as, they are all duplicated from Button 1.
Any ideas what might be causing this issue? I know there are other ways I can do this, but it's bugging me. The radial arrangement works, but the for loop registers 7 visible children and spaces them out based on that number.