I would like to simulate a mouse click on to a texture button via GDScript.
So I tried the following function:
func simulate_btn_click(main_btn):
# main_btn.button is a TextureButton instance
var event = InputEventMouseButton.new()
event.position = main_btn.button.rect_global_position
event.button_index = BUTTON_LEFT
event.pressed = true
get_tree().input_event(event)
event.pressed = false
get_tree().input_event(event)
In this code main_btn.button
is a TextureButton
instance.
Then calling that function like this:
call_deferred("simulate_btn_click", button)
while processing a mouse click on to another button does nothing.
The texture (toggle) button does not change its texture, it's logic is not being processed.
Any ideas what I am missing here?