I have a scene that is a button. If you click on it an instance of that scene (button) is added to that scene. So there are 2 buttons now. Pressing the 1 button creates more buttons. But pressing the instantiated buttons does nothing. What could be the problem? Something related to how signals are connected maybe?

The button's "pressed" signal is connected to the button's script.
func _on_button_pressed():
var child = preload("res://button.tscn").instantiate()
add_child(child)
X.children += 1 // global var to add buttons lower
child.position = Vector2 (0,40*X.children)

    fenisto Can you post your full script and node hierarchy.

    Also, consider having a "container" node that will contain your buttons cause right now you are adding your buttons as childs of other buttons, I don't think it's a good idea.


      Loxyrak There is no more code. And it is just a main node and a button scene as a child.

      If I add children scenes by hand they work. Only instantiated in code ones don't.

        fenisto If I add children scenes by hand they work. Only instantiated in code ones don't.

        Do you have the signal connected through the inspector? Try to connect it in the code.

        Added to print X.children every second. Pressing the instantiated buttons doesn't add to X.children.
        But if I add a process to move them in random directions they move. But they all move in the same direction. So they operate as the same node but only the manually placed ones have signals? I don't get it.

        Saw an error " _parse_ext_resource: res://button.tscn:8 - Parse Error: [ext_resource] referenced non-existent resource at: res://Button.gd"
        Replaced "preload("res://button.tscn").instantiate()" with "load("res://button.tscn").instantiate()"
        Everything is working now.
        Are you not supposed to preload scenes you want to instantiate?

        You preload at the beginning of your script with something like this :

        @onready var button_scene = preload()

        The point of preload is to not have to load the ressource while in gameplay (avoiding lag spikes)