0

I'm trying to make a button within a class constructor in Godot 4. Making them outside works like normal, but when I do it inside a class constructor, pressing them does not run the function connected to them.

Example code for the class:

class test_class:

    func _init(parent):
        var test_button = Button.new()
        test_button.text = "Click me!"
        test_button.connect("pressed",_test_function)
        parent.add_child(test_button)

    func _test_function():
        print("hello")

The button appears when the code is run, and displays the graphical changes of being clicked, but the function does not run. How could I make it run?

1 Answers1

0

I think this is a similar issue, maybe have a read:

connect function

curimania
  • 31
  • 5