The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I am trying to create a game that will display 21 buttons in a GridContainer, but i am not able to change color of button or get assigned value to button. I will need to change the color and value on the fly. as these parameters will change during game play.
all my attempts of changing parameters of buttons result in Error: Attempt to call function 'get' in base 'null instance' on a null instance.
My scene structure is

Godot version 3.5.1
in Engine by (42 points)

1 Answer

0 votes
Best answer

A GridContainer simply manages its direct children. So, assuming your buttons are direct children of the container, you can iterate through them via:

for child in $GridContainer.get_children():

In each iteration of that loop, the child variable will hold a reference the current button. Using that, you can modify any properties associated with that button.

by (22,674 points)
selected by
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.