0 votes

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:

func set_radial_position():
var buttons = get_children()
for button in buttons:
    if !button.is_visible():
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:

enter image description here

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.

in Engine by (78 points)
edited by

1 Answer

0 votes
Best answer

Figured it out.

I was iterating through the initial array size, and during that iteration removing items - which then throws off the iteration count. I solved it by moving visible children to a new array, then using that new array for further calculations.

by (78 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.