diff --git a/core/input/input.cpp b/core/input/input.cpp
index 6b9fec6f6003..e7606da5944d 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -165,6 +165,8 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);
ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input);
ClassDB::bind_method(D_METHOD("is_using_accumulated_input"), &Input::is_using_accumulated_input);
+ ClassDB::bind_method(D_METHOD("set_joypad_enabled", "enable"), &Input::set_joypad_enabled);
+ ClassDB::bind_method(D_METHOD("is_joypad_enabled"), &Input::is_joypad_enabled);
ClassDB::bind_method(D_METHOD("flush_buffered_events"), &Input::flush_buffered_events);
ClassDB::bind_method(D_METHOD("set_emulate_mouse_from_touch", "enable"), &Input::set_emulate_mouse_from_touch);
ClassDB::bind_method(D_METHOD("is_emulating_mouse_from_touch"), &Input::is_emulating_mouse_from_touch);
@@ -173,6 +175,7 @@ void Input::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_mode"), "set_mouse_mode", "get_mouse_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_accumulated_input"), "set_use_accumulated_input", "is_using_accumulated_input");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "joypad_enabled"), "set_joypad_enabled", "is_joypad_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emulate_mouse_from_touch"), "set_emulate_mouse_from_touch", "is_emulating_mouse_from_touch");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emulate_touch_from_mouse"), "set_emulate_touch_from_mouse", "is_emulating_touch_from_mouse");
@@ -362,7 +365,7 @@ static JoyButton _combine_device(JoyButton p_value, int p_device) {
bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const {
_THREAD_SAFE_METHOD_
- if (disable_input) {
+ if (disable_input || !joypad_enabled) {
return false;
}
@@ -507,7 +510,7 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po
float Input::get_joy_axis(int p_device, JoyAxis p_axis) const {
_THREAD_SAFE_METHOD_
- if (disable_input) {
+ if (disable_input || !joypad_enabled) {
return 0;
}
@@ -914,6 +917,9 @@ void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) {
void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
_THREAD_SAFE_METHOD_
+ if (!joypad_enabled) {
+ return;
+ }
if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
return;
}
@@ -927,6 +933,9 @@ void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_st
void Input::stop_joy_vibration(int p_device) {
_THREAD_SAFE_METHOD_
+ if (!joypad_enabled) {
+ return;
+ }
VibrationInfo vibration;
vibration.weak_magnitude = 0;
vibration.strong_magnitude = 0;
@@ -1202,6 +1211,14 @@ bool Input::is_using_accumulated_input() {
return use_accumulated_input;
}
+void Input::set_joypad_enabled(bool p_enable) {
+ joypad_enabled = p_enable;
+}
+
+bool Input::is_joypad_enabled() {
+ return joypad_enabled;
+}
+
void Input::release_pressed_events() {
flush_buffered_events(); // this is needed to release actions strengths
@@ -1224,6 +1241,9 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) {
void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {
_THREAD_SAFE_METHOD_;
+ if (!joypad_enabled) {
+ return;
+ }
Joypad &joy = joy_names[p_device];
ERR_FAIL_INDEX((int)p_button, (int)JoyButton::MAX);
@@ -1251,7 +1271,9 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {
void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
_THREAD_SAFE_METHOD_;
-
+ if (!joypad_enabled) {
+ return;
+ }
ERR_FAIL_INDEX((int)p_axis, (int)JoyAxis::MAX);
Joypad &joy = joy_names[p_device];
@@ -1891,6 +1913,7 @@ Input::Input() {
gravity_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_gravity", false);
gyroscope_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_gyroscope", false);
magnetometer_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_magnetometer", false);
+ joypad_enabled = GLOBAL_DEF_BASIC("input_devices/joypad/joypad_enabled", true);
}
Input::~Input() {
diff --git a/core/input/input.h b/core/input/input.h
index 8d3b7ae3b9cc..7f334b9f8f3e 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -136,6 +136,7 @@ class Input : public Object {
bool emulate_mouse_from_touch = false;
bool agile_input_event_flushing = false;
bool use_accumulated_input = true;
+ bool joypad_enabled = true;
int mouse_from_touch_index = -1;
@@ -388,6 +389,8 @@ class Input : public Object {
void set_agile_input_event_flushing(bool p_enable);
void set_use_accumulated_input(bool p_enable);
bool is_using_accumulated_input();
+ void set_joypad_enabled(bool p_enable);
+ bool is_joypad_enabled();
void release_pressed_events();
diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml
index ca54a44f489a..4af15f9babf1 100644
--- a/doc/classes/Input.xml
+++ b/doc/classes/Input.xml
@@ -433,6 +433,11 @@
If [code]true[/code], sends touch input events when clicking or dragging the mouse. See also [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse].
+
+ If [code]true[/code], enables joypad input events and allows the use of joypad-related functions such as [method Input.is_joy_button_pressed], [method Input.get_joy_axis], [method Input.start_joy_vibration], and [method Input.stop_joy_vibration].
+ See also [member ProjectSettings.input_devices/joypad/joypad_enabled].
+ [b]Note:[/b] Disabling this option does not stop Godot from capturing/connecting to the joypad itself.
+
Controls the mouse mode. See [enum MouseMode] for more information.
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 6d6a4de968b1..280019b5021e 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -1548,6 +1548,12 @@
If [code]false[/code], no input will be lost.
[b]Note:[/b] You should in nearly all cases prefer the [code]false[/code] setting. The legacy behavior is to enable supporting old projects that rely on the old logic, without changes to script.
+
+ If [code]true[/code], enables joypad input events and allows the use of joypad-related functions such as [method Input.is_joy_button_pressed], [method Input.get_joy_axis], [method Input.start_joy_vibration], and [method Input.stop_joy_vibration].
+ This also affects [method Input.is_action_just_pressed], [method Input.is_action_just_released], and [method Input.is_action_pressed].
+ To control this at runtime, use [member Input.joypad_enabled].
+ [b]Note:[/b] Disabling this option does not stop Godot from capturing/connecting to the joypad itself.
+
Specifies the tablet driver to use. If left empty, the default driver will be used.
[b]Note:[/b] The driver in use can be overridden at runtime via the [code]--tablet-driver[/code] [url=$DOCS_URL/tutorials/editor/command_line_tutorial.html]command line argument[/url].
diff --git a/main/main.cpp b/main/main.cpp
index 487addc344be..8b4c0cb741eb 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1489,6 +1489,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
} else if (arg == "--single-threaded-scene") {
single_threaded_scene = true;
+ } else if (arg == "--disable-joypad") {
+ GLOBAL_DEF_BASIC("input_devices/joypad/joypad_enabled", false);
} else if (arg == "--build-solutions") { // Build the scripting solution such C#
auto_build_solutions = true;