Repository navigation
Conversation
…sedThisFrame while another key is held Port of unity/unity trunk PR #135085. anyKey is pressed for as long as any key is held, so a key going down while another one was held never registered as a press. AnyKeyControl now keeps a copy of its key bits (separately for editor and player state) and reports a new press when a key goes down, via a new internal virtual ButtonControl.CheckForRepress. wasReleasedThisFrame still only fires when the last key is released. Adds InputControl.GetStatePtr(InputUpdateType, bool) to read the state of a specific update type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| var endBit = m_StateBlock.bitOffset + m_StateBlock.sizeInBits; | ||
| for (var bit = m_StateBlock.bitOffset; bit < endBit; ++bit) | ||
| { | ||
| if (MemoryHelpers.ReadSingleBit(statePtr, bit) && !MemoryHelpers.ReadSingleBit(lastStatePtr, bit)) |
There was a problem hiding this comment.
Once trigger is being tracked, a WebGL joystick falsely reports wasPressedThisFrame when a held button decreases from 1.0f to 0.75f. WebGLLayoutBuilder.Build uses AnyKeyControl for Trigger, spanning 32-bit float button fields. Changing 1.0f to 0.75f sets a mantissa bit while the aggregate control remains pressed. CheckForRepress interprets that raw bit change as another button press. Restrict bitwise repress detection to actual key-bit state. Preserve aggregate-transition behavior for float-backed AnyKeyControl instances. Add coverage for decreasing a held WebGL button's float value.
🤖 Helpful? 👍/👎
Codecov ReportAttention: Patch coverage is @@ Coverage Diff @@
## develop #2504 +/- ##
===========================================
+ Coverage 78.96% 79.21% +0.24%
===========================================
Files 767 769 +2
Lines 140949 141372 +423
===========================================
+ Hits 111305 111984 +679
+ Misses 29644 29388 -256 Flags with carried forward coverage won't be shown. Click here to find out more.
|
Description
Port of the trunk fix for UUM-144317 (unity/unity PR #135085).
Keyboard.current.anyKey.wasPressedThisFramewas not true when a key went down while another key (e.g. Shift) was already held.anyKeyis anAnyKeyControl, a button that is pressed for as long as any key is held, so holding Shift and then pressing A never transitioned it from released to pressed (there was a////TODO: wasPressedThisFrame and wasReleasedThisFramein the class for this).Changes:
ButtonControlpress tracking (UpdateWasPressed/UpdateWasPressedEditorandBeginTestingForFramePresses) calls a new internal virtualCheckForRepress, which returnsfalseby default, so other buttons are unchanged and there is no public API change.AnyKeyControloverrides it: it keeps a copy of its key bits from the last press-state update (separately for editor and player state) and reports a new press when a key that wasn't down goes down. When press tracking starts, it compares against the previous frame, so the firstwasPressedThisFramequery also catches such a press.InputControl.GetStatePtr(InputUpdateType, bool)reads the state buffers of a given update type.AnyKeyControluses it so the editor and player snapshots never get mixed up when press tracking is refreshed while the other state is current (e.g. after a settings change).wasReleasedThisFramestill only fires when the last key is released, soanyKeycan now report several presses in a row without a release in between. This is documented onAnyKeyControland in the changelog.The code merged cleanly onto
developand matches trunk; the only difference isfixed(spacing from./format.sh.Testing status & QA
New tests in
CoreTests_Devices:Devices_AnyKeyOnKeyboard_WasPressedThisFrame_WhenKeyGoesDownWhileAnotherIsHeld(delta events throughPress/Release)..._WithFullStateEvents(fullKeyboardStateevents, as sent by the platform backends)..._WhenFirstQueriedAsKeyGoesDownWhileAnotherIsHeld(first query in the frame the key goes down)..._KeepsEditorAndPlayerStateApart_WhenSettingsChange(editor only)Not run locally against this branch; relying on CI.
QA: in Play Mode, poll
Keyboard.current.anyKey.wasPressedThisFrameevery frame, hold Shift, then press A — it should be true in the frame A goes down. Releasing A while Shift is still held should report neither a press nor a release.Overall Product Risks
ButtonControlpress tracking is shared by all buttons, though onlyAnyKeyControlchanges behavior.Comments to reviewers
The trunk PR #135085 is approved but not merged yet; this port will be updated if it changes before merging.
Checklist
Before review:
AnyKeyControlremarks updated)During merge:
NEW: ___.FIX: ___.DOCS: ___.CHANGE: ___.RELEASE: 1.1.0-preview.3.🤖 Generated with Claude Code