+1 vote

The global function InputMap.actioneraseevent( 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 )
in Engine by (196 points)

1 Answer

0 votes

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.

https://github.com/bojidar-bg/top-down-inertia/blob/master/main/save_manager.gd#L86

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)

by (1,586 points)
edited by

That's how I fixed it. Thanks anyways :)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.