-
Notifications
You must be signed in to change notification settings - Fork 325
FIX: Changed to frame based comparison for tracking UI click/navigation events #2112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…d approach - track frame of interest in action
WIP - Adding tests - coming soon |
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look like a good approach to fixing the problems with dynamic/fixed and manual update.
I'm a little concerned about having two functions to check the state. In summary as a user I find the naming confusing and hard to tell if I when to use WasPressed vs WasPressedThisFrame Adding a another reviewer for input. |
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs
Outdated
Show resolved
Hide resolved
Another option would be to just at a boolean parameter to each API piece wheather to check the dynamic Update cycle (which could default to true).
I understand the concerns, I couldn't make up a better name for it since WasPressedThisUpdate() would be misleading since Update could be wrongly interpreted as dynamic Update again. |
@@ -87,9 +87,9 @@ public void Actions_WhenShortcutsDisabled_AllConflictingActionsTrigger() | |||
Press(keyboard.wKey); | |||
|
|||
// All Actions were triggered | |||
Assert.That(action1.WasPerformedThisFrame()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of tests update to make this pass?
Were all these failing without the changes?
Make me worry about how much customer code would be impacted by the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test run without mimiking the dynamic update, which make this call wrong in it self (ThisFrame). Either they need to use Coroutines (see comment above) or rely on InputSystem.Update manual updates like here. In real settings (non test environments) there are no such requirements, so I don't think the users will be impacted. Especially because most users rely on update, which will work just like before.
What I meant with previous question/comment is that, considering e.g. this sequence, the results vary depending on what frame corresponds to right? Mainly adding this comment to support discussion.
|
…r-update-non-dynamic # Conflicts: # Packages/com.unity.inputsystem/CHANGELOG.md
…ub.com/Unity-Technologies/InputSystem into fix-ui-behavior-for-update-non-dynamic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems version is correct now given API additions which made CI green, great.
The only two remaining things I can spot or think of now is:
- Why isn't this called out also under #Added in changelog since the PR is adding functionality not previously available?
- This risk on this PR is quite high so curious whether UI or XR QA or devs have been involved at any point since it may likely also have halo effects into e.g. XRI and UI related solutions?
Will approve now but consider extending CHANGELOG and/or reach out to UI and/or XR maybe before landing it?
Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs
Outdated
Show resolved
Hide resolved
…r-update-non-dynamic # Conflicts: # Assets/Samples/InGameHints/InGameHintsActions.cs # Assets/Samples/SimpleDemo/SimpleControls.cs # Assets/Tests/InputSystem/InputActionCodeGeneratorActions.cs # Packages/com.unity.inputsystem/InputSystem/AssemblyInfo.cs # Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastKeyboard.cs # Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastMouse.cs # Packages/com.unity.inputsystem/InputSystem/Devices/Precompiled/FastTouchscreen.cs # Packages/com.unity.inputsystem/Tests/TestFixture/AssemblyInfo.cs # Packages/com.unity.inputsystem/package.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation on WasPerformedThisDynamicUpdate says that
If the update mode is set to
InputSettings.UpdateMode.ProcessEventsInDynamicUpdate
, this method will behave exactly likeWasPerformedThisFrame
.
however that is not the behavior I'm seeing when I set up a test example.
I created a MonoBehaviour that uses an early execution order that ensures it runs before any of my other scripts:
[DefaultExecutionOrder(-31001)]
public class ManualInputTicker : MonoBehaviour
{
protected void Update()
{
if (InputSystem.settings.updateMode != InputSettings.UpdateMode.ProcessEventsManually)
return;
InputSystem.Update();
}
}
In my setup, the Input Action is just a very basic "Button" Action Type action with a basic <XRController>{RightHand}/{GripButton}
binding without any other modifications.
When Input System settings are set to Process Events In Dynamic Update, the different ways of checking input is a match. However, when I set it to Process Events Manually, I get an unexpected frame delay when checking WasPerformedThisFrame
/WasPerformedThisDynamicUpdate
. In the screenshots, when I pressed the grip button, the WasPerformedThisFrame
goes true on frame 223 in my example, but WasPerformedThisDynamicUpdate
only goes true on frame 224. When I released the grip button, same frame delay outcome with WasCompletedThisFrame
going true on frame 372 but WasCompletedThisDynamicUpdate
going true on frame 373.
(I can go over my test setup in a Zoom call if needed, but in these logs pF:
means WasPerformedThisFrame/WasPerformedThisDynamicUpdate and pC:
means WasCompletedThisFrame/WasCompletedThisDynamicUpdate
)
I would expect that if my code manually calls InputSystem.Update
during Update when the project settings are set to Manually Update, it should apply within that same frame to match the other methods. But maybe my assumption is incorrect and this is actually working as designed?
Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Massie <[email protected]>
Co-authored-by: Chris Massie <[email protected]>
Co-authored-by: Chris Massie <[email protected]>
Co-authored-by: Chris Massie <[email protected]>
Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Chris Massie <[email protected]>
…ub.com/Unity-Technologies/InputSystem into fix-ui-behavior-for-update-non-dynamic # Conflicts: # Packages/com.unity.inputsystem/InputSystem/Editor/Settings/InputSettingsProvider.cs
Description
During investigating ISXB-1313 it got clear that catching navigation and click events does not work properly once InputSystem is set to a custom / Fixed Update mode.
Analysis:
The main reason for this is that the InputSystemUIInputModule (Process -> ProcessNavigation -> WasPerformedThisFrame) is automatically called in dynamic Update, this calls in
WasPressedThisFrame()
WasReleasedThisFrame()
WasCompletedThisFrame()
WasPerformedThisFrame()
to check weather UI actions were triggered. Internally those methods use
pressedInUpdate
releasedInUpdate
lastPerformedInUpdate
lastCompletedInUpdate
which are properties to track at which update cycle of the InputSystem the events triggered. All above are just used for this checks.
Problem:
The update step is not comparable at the time of the dynamic Update since it is not clear how many times InputSystem.Update() (and with that the current update step was incremented by 1) was called in between two dynamic Updates. It can be incremented by 1 customly every millisecond or switched to be called in FixedUpdate.
Solution:
The solution is to have two different methods for the (WasPressedThisFrame/WasPerformedThisFrame ...)checks, where one checks for the current frame only and the other for the input update cycle.
They will be equal if the update mode is set to dynamic Update, if set to FixedUpdate or Manual update eg WasPressedThisRenderingFrame will return only true if the action was pressed this dynamic update cycle (no matter in which cycle the InputSystem is updated). This was missing since the old approach was assuming a frame based input updating and would not return valid values if updating the InputSystem would happen in any other time cycle.
InputSystemUIInputModule calls in the WasPerformedThisRenderingFrame() now, which returns valid results independent of the InputSetting during the dynamic Update.
Decoupling the rendering frame count checking from the input update count checking is one essential part of this PR. Those two values are only related if the input update mode is set to dynamic Update (in fact they are the same in this case). In any other case they don't have anything in common. Checking when an action state was changed can happen in the same time cycle like updating the InputSystem (which can now be decoupled from the dynamic Update).
See more details in this technical discussion document.
Testing status & QA
testing in InputSystem repo, bug project (attached to ISXB-1313) and against https://jira.unity3d.com/browse/ISXB-1160
https://jira.unity3d.com/browse/ISXB-1141.
Overall Product Risks
Comments to reviewers
For further explanation also check the comments in the ticket.
Checklist
Before review:
Changed
,Fixed
,Added
sections.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.After merge: