Input(event) trouble

Godot Version



Hi everyone,

this function in my Sprite’s script works fine:

func _input(event):
   if Input.is_action_just_pressed("mousebuttonclick") && get_rect().has_point(to_local(event.position)):
      do something

Now I’d like this function to be “triggered remotely” by a button-press:

func _on_button_down():

Unfortunately this doesn’t work and an error is thrown: The identifier "event" isn't declared in the current scope.
How can I get this to work?

You will need an event in order to call the input function. You can technically make an event with Input.parse_input_event but I think it would be simpler to just wrap “do something” in a function and then call that function.

Thanks for your suggestions. I didn’t know about “parse_input_event”, but it appears quite promising!


is accessible everywhere. From inside the _input(event) function, it’s easier to call:

if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:

Rather than trying to call the _input(event) function, you could wrap your action in its own function and call it after either action.

If “mousebuttonclick”:
If “ui_down”:

OR you can use nested IF statements:

If “mousebuttonclick” || “ui_down”:
If get_rect()…:
# DoSomething