0 votes
   extends Button
var arg=[]
func ready():
    arg.resize(76)
    for i in range(arg.size()):
        var button = Button.new()
        add_child(button)
        button.set_size(Vector2(64,64))
        button.connect("pressed", self, "myrotate", [i])
        $button["custom_styles/normal"].bg_color = Color("#bada55")
        button.show()
        arg.insert(i, button)
    arg[0].set_position(Vector2(192,64))
    arg[1].set_position(Vector2(256,64))

Created buttons aren't showing on screen when I start the game. It's not showing any errors either. Any and all help is apreciated.

Godot version 3.5
in Engine by (24 points)

2 Answers

0 votes
Best answer

For anyone having the same problem, you shouldn't add button as a child of another button. Add it as a child of a control node. There are some minor syntax mistakes also in my code. So here is how it looks now, it still has problems like rotating it, but visibility is ok.

extends Control
var arg=[]

    func _ready():
        arg.resize(76)
        for i in range(arg.size()):
            var button = TextureButton.new()
            button.set_rotation_degrees(0)
            button.set_size(Vector2(64,64))
            button.texture_normal = load("res://cijev.png");
            button.connect("pressed", self, "myrotate", [i])
            arg.insert(i, button)
            add_child(arg[i])
            setposition(i)
by (24 points)

Discord community helpen in solving this.

0 votes

Put a child in the button.

in "add_child(button)"

put a way

example:
"$".".add_child(button)"

and use a visible
button.visible = true

if the button dont appears anyways, try put a position in the button.

by (26 points)
extends Button

var arg=[]

func ready():
    arg.resize(76)
    for i in range(arg.size()):
        var button = Button.new()
        $Button.add_child(button)
        button.set_size(Vector2(64,64))
        button.visible=true
        button.connect("pressed", self, "myrotate", [i])
        $button["custom_styles/normal"].bg_color = Color("#bada55")
        button.show()
        arg.insert(i, button)
    arg[0].set_position(Vector2(192,64))
    arg[1].set_position(Vector2(256,64))

I tried what you said, it still isn't showing. Maybe I missunderstood you. Is it supposed to be like this? I cut out the code with positions of the buttons. Each one of them had a position.

$Button is wrong.

try use

gettree().root.addchild(button)

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.