Recently, I’ve been working on a solo indie project, and to implement control rebinding I followed a tutorial by The Coffee Crow ( https://www.youtube.com/watch?v=vNQBFn0faws ) and I’ve run into a bug where whenever I run the game and try to rebind any of the controls, the game crashes, I will put my code bellow and give as much information as I can.
`class_name HotkeyRebindButton
extends Control
@onready var label: Label = $HBoxContainer/Label as Label
@onready var button: Button = $HBoxContainer/Button as Button
@export var action_name : String = “Walk_left”
func _ready() → void:
set_process_unhandled_key_input(false)
set_action_name()
set_text_for_key()
func set_action_name() → void:
label.text = “Unassigned”
# This names the buttons in the controls menu
match action_name:
“Walk_left”:
label.text = “Walk Left”
“Walk_rigth”:
label.text = “Walk Rigth”
“Jump”:
label.text = “Jump”
func set_text_for_key() → void:
var action_events = InputMap.action_get_events(action_name)
var action_event = action_events[0]
var action_keycode = OS.get_keycode_string(action_event.physical_keycode)
button.text = "%s" % action_keycode
func _on_button_toggled(button_pressed):
if button_pressed:
button.text = “Press any key…”
set_process_unhandled_input(button_pressed)
for i in get_tree().get_nodes_in_group("hotkey_button"):
if i.action_name != self.action_name:
i.button.toggle_mode = true
i.set_process_unhandled_input(false)
else:
for i in get_tree().get_nodes_in_group("hotkey_button"):
if i.action_name != self.action_name:
i.button.toggle_mode = false
i.set_process_unhandled_input(false)
set_text_for_key()
func _unhandled_key_input(event):
rebind_action_key(event)
button.button_pressed = false
func rebind_action_key(event) → void:
InputMap.action_erase_events(action_name)
InputMap.action_add_event(action_name, event)
set_process_unhandled_key_input(false)
set_text_for_key()
set_action_name()
`
the console tells me the error is
"E 0:00:03:171 HotkeyRebindButton._on_button_toggled: Invalid access to property or key ‘action_name’ on a base object of type ‘Button’.
hotkey_rebind_button.gd:39 @ HotkeyRebindButton._on_button_toggled()
hotkey_rebind_button.gd:39 @ _on_button_toggled() "
and the hotkey_button group said in the tutorial is in the “HotKeyRebindButton” control node as a global group, if anyone could explain what is the error I would be extremely thankfull as I am really really new to not just godot but programing in general. Thank you in advance!