How to use InputMap.action_erase_event()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By twinpixel
:warning: 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 )
:bust_in_silhouette: Reply From: Bojidar Marinov

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)

That’s how I fixed it. Thanks anyways :slight_smile:

twinpixel | 2016-03-07 14:24

It’s been fixed in the git master, action_erase_event() now works as expected :slight_smile:

Hinsbart | 2016-03-07 18:17