Topic was automatically imported from the old Question2Answer platform.
Asked By
Hammer Bro.
I’d like to emit InputActions via GDScript – I want certain logic to control UI events and I don’t want to have to add code to every UI-aware component in Godot.
But most of the answers to this question suggest calling get_tree().input_event(InputEvent), which is now deprecated. Should not be called manually, override _input_event() instead. Will be removed in Godot 4.0. But it looks like overriding that will only allow me to react to these script-generated Actions in the main loop’s code. My goal is to emit Actions which are picked up by all _input(InputEvent) functions, as well as the built-in UI elements.
What’s the recommended means of generating Actions via GDScript in Godot 3.2+?
extend InputEventAction in your custom class then use Input.parse_input_event(my_custom_action)
class custom_action extends InputEventAction:
_init():
pass
var my_custom_action = custom_action.new()
Input.parse_input_event(my_custom_action)
or
#used to send
Input.action_press("my_custom_action")
Input.action_release("my_custom_action")
#used to receive
if Input.is_action_pressed("my_custom_action"):
foo()
Fantastic, Input.parse_input_event(InputEvent) and InputEventAction were what I was missing. You don’t even have to create a custom class, you can just do InputEventAction.new() and specify its properties.
Hammer Bro. | 2021-02-22 02:09
While True the custom class allows you to add additional content like for example a twist gesture would have the direction of rotation which is not present in the base InputEventAction