diff --git a/Assets/Tests/InputSystem/CoreTests_Devices.cs b/Assets/Tests/InputSystem/CoreTests_Devices.cs
index 03fe00c679..070b1c7ce9 100644
--- a/Assets/Tests/InputSystem/CoreTests_Devices.cs
+++ b/Assets/Tests/InputSystem/CoreTests_Devices.cs
@@ -4394,6 +4394,15 @@ public void Devices_CanSetPollingFrequency()
Assert.That(InputSystem.pollingFrequency, Is.EqualTo(120).Within(0.000001));
}
+ #if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
+ [Test]
+ [Category("Devices")]
+ public void Devices_PollingFrequencyIsAtLeast60HzByDefault()
+ {
+ Assert.That(InputSystem.pollingFrequency, Is.GreaterThanOrEqualTo(60));
+ }
+
+ #else
[Test]
[Category("Devices")]
public void Devices_PollingFrequencyIs60HzByDefault()
@@ -4403,6 +4412,8 @@ public void Devices_PollingFrequencyIs60HzByDefault()
Assert.That(runtime.pollingFrequency, Is.EqualTo(60).Within(0.000001));
}
+ #endif
+
[Test]
[Category("Devices")]
public unsafe void Devices_CanInterceptAndHandleDeviceCommands()
diff --git a/Assets/Tests/InputSystem/Unity.InputSystem.Tests.asmdef b/Assets/Tests/InputSystem/Unity.InputSystem.Tests.asmdef
index 37981b1ea9..01abd0ac01 100644
--- a/Assets/Tests/InputSystem/Unity.InputSystem.Tests.asmdef
+++ b/Assets/Tests/InputSystem/Unity.InputSystem.Tests.asmdef
@@ -65,6 +65,11 @@
"name": "Unity",
"expression": "6000.0.15",
"define": "UNITY_INPUT_SYSTEM_SENDPOINTERHOVERTOPARENT"
+ },
+ {
+ "name": "Unity",
+ "expression": "6000.3.0a3",
+ "define": "UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY"
}
],
"noEngineReferences": false
diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md
index e9e79a41f1..b8b2334f9b 100644
--- a/Packages/com.unity.inputsystem/CHANGELOG.md
+++ b/Packages/com.unity.inputsystem/CHANGELOG.md
@@ -69,6 +69,7 @@ however, it has to be formatted properly to pass verification tests.
### Changed
- Changed default input action asset name from New Controls to New Actions.
- Added disabling of action maps in rebinding UI sample.
+- `InputSystem.pollingFrequency` is now initialized based on recommended polling frequency by the underlying platform on Unity versions newer than 6000.3.0a1. It can still be customized (set) during run-time as usual. Increasing polling frequency beyond the default 60Hz leads to less probability of input loss and reduces input latency.
### Added
- An alternative way to access if an action state reached a certain phase during this rendering frame (Update()). This can be utilized even if the InputSystem update mode is set to manual or FixedUpdate. It can be used to access the action phase during rendering, eg for perform updates to the UI.
diff --git a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs
index 8940f888c6..367e1189ca 100644
--- a/Packages/com.unity.inputsystem/InputSystem/InputManager.cs
+++ b/Packages/com.unity.inputsystem/InputSystem/InputManager.cs
@@ -197,16 +197,28 @@ public InputSettings.ScrollDeltaBehavior scrollDeltaBehavior
public float pollingFrequency
{
- get => m_PollingFrequency;
+ get
+ {
+ #if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
+ return m_Runtime.pollingFrequency;
+ #else
+ return m_PollingFrequency;
+ #endif
+ }
+
set
{
////REVIEW: allow setting to zero to turn off polling altogether?
if (value <= 0)
throw new ArgumentException("Polling frequency must be greater than zero", "value");
+ #if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
+ m_Runtime.pollingFrequency = value;
+ #else
m_PollingFrequency = value;
if (m_Runtime != null)
m_Runtime.pollingFrequency = value;
+ #endif
}
}
@@ -1888,8 +1900,10 @@ internal void InitializeData()
m_ScrollDeltaBehavior = InputSettings.ScrollDeltaBehavior.UniformAcrossAllPlatforms;
+ #if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
// Default polling frequency is 60 Hz.
m_PollingFrequency = 60;
+ #endif
// Register layouts.
// NOTE: Base layouts must be registered before their derived layouts
@@ -2141,7 +2155,9 @@ internal struct AvailableDevice
// Used by EditorInputControlLayoutCache to determine whether its state is outdated.
internal int m_LayoutRegistrationVersion;
+ #if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
private float m_PollingFrequency;
+ #endif
internal InputControlLayout.Collection m_Layouts;
private TypeTable m_Processors;
@@ -4092,7 +4108,9 @@ internal SerializedState SaveState()
return new SerializedState
{
layoutRegistrationVersion = m_LayoutRegistrationVersion,
+ #if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
pollingFrequency = m_PollingFrequency,
+ #endif
devices = deviceArray,
availableDevices = m_AvailableDevices?.Take(m_AvailableDeviceCount).ToArray(),
buffers = m_StateBuffers,
@@ -4118,7 +4136,9 @@ internal void RestoreStateWithoutDevices(SerializedState state)
updateMask = state.updateMask;
scrollDeltaBehavior = state.scrollDeltaBehavior;
m_Metrics = state.metrics;
+ #if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
m_PollingFrequency = state.pollingFrequency;
+ #endif
if (m_Settings != null)
Object.DestroyImmediate(m_Settings);
diff --git a/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs b/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs
index 189c4b6e50..ddcf67418e 100644
--- a/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs
+++ b/Packages/com.unity.inputsystem/InputSystem/InputSystem.cs
@@ -1364,7 +1364,7 @@ public static event InputDeviceFindControlLayoutDelegate onFindLayoutForDevice
/// The unit is Hertz. A value of 120, for example, means that devices are sampled 120 times
/// per second.
///
- /// The default polling frequency is 60 Hz.
+ /// The default polling frequency is at least 60 Hz or what is suitable for the target device.
///
/// For devices that are polled, the frequency setting will directly translate to changes in the
/// patterns. At 60 Hz, for example, timestamps for a specific,
diff --git a/Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs b/Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs
index 7c6b2090ce..6ee7e59f1f 100644
--- a/Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs
+++ b/Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs
@@ -211,10 +211,16 @@ public Action onPlayerFocusChanged
public float pollingFrequency
{
+ #if UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
+ get => NativeInputSystem.GetPollingFrequency();
+ #else
get => m_PollingFrequency;
+ #endif
set
{
+ #if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
m_PollingFrequency = value;
+ #endif
NativeInputSystem.SetPollingFrequency(value);
}
}
@@ -246,7 +252,12 @@ public bool runInBackground
#if UNITY_EDITOR
private Action m_PlayerLoopInitialization;
#endif
+ #if !UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY
+ // From Unity 6000.3.0a2 (TODO Update comment and manifest before landing PR) this is handled by module
+ // and initial value is suggested by the platform based on its supported device set.
+ // In older version this is stored here and package override module/platform.
private float m_PollingFrequency = 60.0f;
+ #endif
private bool m_DidCallOnShutdown = false;
private void OnShutdown()
{
diff --git a/Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef b/Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef
index cbf773a654..f57a96d465 100644
--- a/Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef
+++ b/Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef
@@ -111,6 +111,11 @@
"name": "com.unity.modules.unityanalytics",
"expression": "1",
"define": "UNITY_INPUT_SYSTEM_ENABLE_ANALYTICS"
+ },
+ {
+ "name": "Unity",
+ "expression": "6000.3.0a3",
+ "define": "UNITY_INPUT_SYSTEM_PLATFORM_POLLING_FREQUENCY"
}
],
"noEngineReferences": false