Topic was automatically imported from the old Question2Answer platform.
Asked By
twinpixel
Old Version
Published before Godot 3 was released.
The global function InputMap.action_erase_event( String action, InputEvent event ) seems not to do anything or am I doing something wrong?
For example I want to delete all keyboard events (evtype = 1):
func delete_events(actionname, evtype):
var list = InputMap.get_action_list( actionname )
for i in list:
if i.type == evtype:
InputMap.action_erase_event( actionname, i )
It seems like there was a bug with this function on 2.0.1 and below, after that it was fixed, and it didn’t work properly.
Some time ago, I was trying to do something similar (actually, to make actions rebindable), and the best workaround I found was to delete the whole action, and recreate it.
var event = InputEvent()
event.type = InputEvent.KEY
event.scancode = scancode
for old_event in InputMap.get_action_list(action_name):
InputMap.action_erase_event(action_name, old_event)
if InputMap.get_action_list(action_name).size() > 0:
InputMap.erase_action(action_name)
InputMap.add_action(action_name)
InputMap.action_add_event(action_name, event)
(Note that if this bug gets fixed, the above code would start working a bit faster)
(Bug fixed by @Hinsbart, YAY)