Переглянути джерело

Merge pull request #95750 from mosquitochang/fix-input-event-get-index

Fix `InputMap::event_get_index` to handle unmatched events correctly
Rémi Verschelde 8 місяців тому
батько
коміт
be4678b836
1 змінених файлів з 2 додано та 2 видалено
  1. 2 2
      core/input/input_map.cpp

+ 2 - 2
core/input/input_map.cpp

@@ -254,8 +254,8 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName
 
 int InputMap::event_get_index(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match) const {
 	int index = -1;
-	event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
-	return index;
+	bool valid = event_get_action_status(p_event, p_action, p_exact_match, nullptr, nullptr, nullptr, &index);
+	return valid ? index : -1;
 }
 
 bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *r_pressed, float *r_strength, float *r_raw_strength, int *r_event_index) const {