Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9f411e7
Reverted explicit value initialization to avoid false positive failur…
chris-massie Oct 30, 2023
9d4f808
Added valueType property to InputAction, allowing access to it outsid…
chris-massie Oct 30, 2023
b8042e3
Renamed to make it clear it functions like activeControl where it can…
chris-massie Oct 30, 2023
13cd9ad
Added test using dynamic composite type to verify activeValueType is …
chris-massie Oct 30, 2023
acbaf8b
Added ignore rule of file generated in Editor_LeavingPlayMode_Discard…
chris-massie Oct 30, 2023
0aa780c
Added WasUnperformedThisFrame for the counterpart to WasPerformedThis…
chris-massie Oct 31, 2023
11b6e30
Updated methods to pass along the phase after canceled so it can know…
chris-massie Nov 1, 2023
10cc4b7
Added tests for WasPerformedThisFrame/WasUnperformedThisFrame along w…
chris-massie Nov 1, 2023
4c61a30
fix for neutron CI warning (#1787)
ritamerkl Nov 1, 2023
a9a4fbc
Readded old test to make the diff of this branch easier to understand
chris-massie Nov 1, 2023
fa5f304
FIX: UITK Listen button not working with Any control types (#1788)
jamesmcgill Nov 2, 2023
bdf35ae
Fixed missing ) in code example
chris-massie Nov 3, 2023
7114672
Added GetMagnitude method for getting the magnitude of the active com…
chris-massie Nov 3, 2023
fbee9b1
CHANGE: Restructured main Input System Package settings nodes when Pr…
ekcoh Nov 4, 2023
70d769a
CHANGE: Make Project-wide Actions the default for Player Input (#1790)
jfreire-unity Nov 6, 2023
23e4fe7
Added test using a hold action where it demonstrates the difference b…
chris-massie Nov 6, 2023
5e03d52
Modified test to test against Value, Button, and PassThrough and addi…
chris-massie Nov 6, 2023
d03fd6a
Fixed xml-docs
chris-massie Nov 6, 2023
3e6eb30
Added method for finding an InputAction by Guid ID
chris-massie Nov 7, 2023
4c9f7fd
FIX: Ensure UITK Editor restores selection after domain reload (#1794)
jamesmcgill Nov 7, 2023
7ae7114
FIX: Temporary fix to avoid exceptions being thrown by `InputControlP…
Secticide Nov 7, 2023
4becc1a
NEW: Add option to reset project-wide actions to original state (ISX-…
ritamerkl Nov 7, 2023
e19cce1
Merge branch 'develop' into add-unperformed
chris-massie Nov 7, 2023
75a967a
Fixed error in docs where it incorrectly said Pass-Through actions wi…
chris-massie Nov 7, 2023
723d912
Added manual docs for WasUnperformedThisFrame
chris-massie Nov 7, 2023
a7fae0b
Merge branch 'develop' into add-unperformed
chris-massie Nov 8, 2023
8484bba
Readded docs for WasUnperformedThisFrame to new documentation file af…
chris-massie Nov 8, 2023
ad54061
Fixed case of MonoBehaviour and made it code style
chris-massie Nov 8, 2023
1dd0f27
Updated examples for polling and fixed pressed example wording to be …
chris-massie Nov 8, 2023
bc95814
Added changelog entries
chris-massie Nov 8, 2023
64b9336
Fixed doc links to InputActionPhase
chris-massie Nov 9, 2023
f26684e
Merge branch 'develop' into add-unperformed
chris-massie Nov 9, 2023
bb8f009
Moved changelog entries to new Unreleased section after release of 1.…
chris-massie Nov 9, 2023
8e97bc9
Fixed code formatting
chris-massie Nov 9, 2023
d3416ae
Merge branch 'develop' into add-unperformed
chris-massie Nov 13, 2023
efecae3
Merge branch 'develop' into add-unperformed
chris-massie Nov 21, 2023
3d58615
Apply suggestions from code review
chris-massie Nov 22, 2023
51f3b04
Removed new FindAction method based on PR feedback that it exposes to…
chris-massie Dec 15, 2023
bdbf2e5
Replaced blank with F for false
chris-massie Dec 15, 2023
8dc8034
Updated xml-docs for clarity based on PR feedback
chris-massie Dec 15, 2023
6c71b9c
Added legend for T and F in the test comments
chris-massie Dec 15, 2023
ddd562c
Renamed test to make it more apparent that it's testing edge cases wi…
chris-massie Dec 15, 2023
c2f8e1f
Added a new short test to verify unperformed with a hold interaction …
chris-massie Dec 15, 2023
b671d27
Added link to Sector interaction in XRI docs
chris-massie Dec 15, 2023
221fa47
Renamed Unperformed to Completed
chris-massie Dec 16, 2023
dfd8bc2
Merge branch 'develop' into add-unperformed
chris-massie Dec 16, 2023
c982a6d
Fixed extra whitespace
chris-massie Dec 18, 2023
628044d
Renamed method from WasUnperformedThisFrame to WasCompletedThisFrame …
chris-massie Dec 18, 2023
954692b
Merge branch 'develop' into add-unperformed
ekcoh Jan 11, 2024
680b2e6
Merge branch 'develop' into add-unperformed
chris-massie Jan 11, 2024
06e8bd8
Merge branch 'develop' into add-unperformed
lyndon-unity Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ docerrors.log

Assets/**/*.api
Assets/**/*.api.meta
Assets/__TestInputAsset.inputactions
Assets/__TestInputAsset.inputactions.meta

Packages/packages-lock.json
Packages/com.unity.inputsystem/artifacts/**
Expand Down
1,401 changes: 1,384 additions & 17 deletions Assets/Tests/InputSystem/CoreTests_Actions.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ however, it has to be formatted properly to pass verification tests.
### Changed
- From 2023.2 forward: UI toolkit now uses the "UI" action map of project-wide actions as their default input actions. Previously, the actions were hardcoded and were based on `DefaultInputActions` asset which didn't allow user changes. Also, removing bindings or renaming the 'UI' action map of project wide actions will break UI input for UI toolkit.

### Added
- Added new methods and properties to [`InputAction`](xref:UnityEngine.InputSystem.InputAction):
- [`InputAction.activeValueType`](xref:UnityEngine.InputSystem.InputAction.activeValueType) returns the `Type` expected by `ReadValue<TValue>` based on the currently active control that is driving the action.
- [`InputAction.GetMagnitude`](xref:UnityEngine.InputSystem.InputAction.GetMagnitude) returns the current amount of actuation of the control that is driving the action.
- [`InputAction.WasCompletedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasCompletedThisFrame) returns `true` on the frame that the action stopped being in the performed phase. This allows for similar functionality to [`WasPressedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasPressedThisFrame)/[`WasReleasedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasReleasedThisFrame) when paired with [`WasPerformedThisFrame`](xref:UnityEngine.InputSystem.InputAction.WasPerformedThisFrame) except it is directly based on the interactions driving the action. For example, you can use it to distinguish between the button being released or whether it was released after being held for long enough to perform when using the Hold interaction.

### Fixed
- Fixed syntax of code examples in API documentation for [`AxisComposite`](xref:UnityEngine.InputSystem.Composites.AxisComposite).
- Fixed missing confirmation popup when deleting a control scheme.
- Fixed support for menu bar/customisable keyboard shortcuts used when interacting with Actions and Action Maps.
- Fixed add bindings button to support left button click.
Expand Down
4 changes: 2 additions & 2 deletions Packages/com.unity.inputsystem/Documentation~/Interactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ An Interaction has a set of distinct phases it can go through in response to rec
|`Waiting`|The Interaction is waiting for input.|
|`Started`|The Interaction has been started (that is, it received some of its expected input), but is not complete yet.|
|`Performed`|The Interaction is complete.|
|`Canceled`|The Interaction was interrupted and aborted. For example, the user pressed and then released a button before the minimum time required for a [hold Interaction](#hold) to complete.|
|`Canceled`|The Interaction was interrupted and aborted. For example, the user pressed and then released a button before the minimum time required for a [hold Interaction](#hold) to complete.|

Not every Interaction triggers every phase, and the pattern in which specific Interactions trigger phases depends on the Interaction type.

Expand Down Expand Up @@ -163,7 +163,7 @@ If you haven't specifically added an Interaction to a Binding or its Action, the

|__Callback__|[`InputActionType.Value`](RespondingToActions.md#value)|[`InputActionType.Button`](RespondingToActions.md#button)|[`InputActionType.PassThrough`](RespondingToActions.md#pass-through)|
|-----------|-------------|------------|-----------------|
|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control(s) changed value away from the default value.|Button started being pressed but has not necessarily crossed the press threshold yet.|First Control actuation after Action was enabled.|
|[`started`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_started)|Control(s) changed value away from the default value.|Button started being pressed but has not necessarily crossed the press threshold yet.|not used|
|[`performed`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_performed)|Control(s) changed value.|Button was pressed to at least the button [press threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint).|Control changed value.|
|[`canceled`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_canceled)|Control(s) are no longer actuated.|Button was released. If the button was pressed above the press threshold, the button has now fallen to or below the [release threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_buttonReleaseThreshold). If the button was never fully pressed, the button is now back to completely unpressed.|Action is disabled.|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

There are two main techniques you can use to respond to Actions in your project. These are to either use **polling** or an **event-driven** approach.

- The **Polling** approach refers to the technique of repeatedly checking the current state of the Actions you are interested in. Typically you would do this in the Update() method of a Monobehaviour script.
- The **Polling** approach refers to the technique of repeatedly checking the current state of the Actions you are interested in. Typically you would do this in the `Update()` method of a `MonoBehaviour` script.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely related to this PR, but maybe we should provide some additional guidance here that polling may be used when the order of actions performed is irrelevant, while event-driven callback approach is appropriate when order of actions during a frame is relevant or what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was still frame based? Does Input System actually know if A was pressed before B if they were both pressed in the same frame?

I don't think I know enough about the details to update the documentation about that in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When observing events yes, but not when using polling APIs. I will take a separate. note on addressing this.

- The **Event-driven** approach involves creating your own methods in code that are automatically called when an action is performed.

For most common scenarios, especially action games where the user's input should have a continuous effect on an in-game character, **Polling** is usually simpler and easier to implement.
Expand Down Expand Up @@ -39,27 +39,40 @@ public class Example : MonoBehaviour

Note that the value type has to correspond to the value type of the control that the value is being read from.

To determine whether an action was performed in the current frame, you can use [`InputAction.WasPerformedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPerformedThisFrame):
There are two methods you can use to poll for `performed` [action callbacks](#action-callbacks) to determine whether an action was performed or stopped performing in the current frame.

These methods differ from [`InputAction.WasPressedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPressedThisFrame) and [`InputAction.WasReleasedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasReleasedThisFrame) in that these depend directly on the [Interactions](Interactions.md) driving the action (including the [default Interaction](Interactions.md#default-interaction) if no specific interaction has been added to the action or binding).

|Method|Description|
|------|-----------|
|[`InputAction.WasPerformedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPerformedThisFrame)|True if the [`InputAction.phase`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_phase) of the action has, at any point during the current frame, changed to [`Performed`](../api/UnityEngine.InputSystem.InputActionPhase.html#UnityEngine_InputSystem_InputActionPhase_Performed).|
|[`InputAction.WasCompletedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasCompletedThisFrame)|True if the [`InputAction.phase`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_phase) of the action has, at any point during the current frame, changed away from [`Performed`](../api/UnityEngine.InputSystem.InputActionPhase.html#UnityEngine_InputSystem_InputActionPhase_Performed) to any other phase. This can be useful for [Button](#button) actions or [Value](#value) actions with interactions like [Press](Interactions.md#press) or [Hold](Interactions.md#hold) when you want to know the frame the interaction stops being performed. For actions with the [default Interaction](Interactions.md#default-interaction), this method will always return false for [Value](#value) and [Pass-Through](#pass-through) actions (since the phase stays in [`Started`](../api/UnityEngine.InputSystem.InputActionPhase.html#UnityEngine_InputSystem_InputActionPhase_Started) for Value actions and stays in [`Performed`](../api/UnityEngine.InputSystem.InputActionPhase.html#UnityEngine_InputSystem_InputActionPhase_Performed) for Pass-Through).|

This example uses the Interact action from the [default actions](ActionsEditor.md#the-default-actions), which has a [Hold](Interactions.md#hold) interaction to make it perform only after the bound control is held for a period of time (for example, 0.4 seconds):

```CSharp
using UnityEngine;
using UnityEngine.InputSystem;

public class Example : MonoBehaviour
{
InputAction jumpAction;
InputAction interactAction;

private void Start()
{
jumpAction = InputSystem.actions.FindAction("Jump");
interactAction = InputSystem.actions.FindAction("Interact");
}

void Update()
{
if (jumpAction.WasPerformedThisFrame())
if (interactAction.WasPerformedThisFrame())
{
// your code to respond to the Jump action here
// your code to respond to the first frame that the Interact action is held for enough time
}

if (interactAction.WasCompletedThisFrame())
{
// your code to respond to the frame that the Interact action is released after being held for enough time
}
}
}
Expand All @@ -73,7 +86,7 @@ Finally, there are three methods you can use to poll for button presses and rele
|[`InputAction.WasPressedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasPressedThisFrame)|True if the level of [actuation](../api/UnityEngine.InputSystem.InputControl.html#UnityEngine_InputSystem_InputControl_EvaluateMagnitude) on the action has, at any point during the current frame, reached or gone above the [press point](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint).|
|[`InputAction.WasReleasedThisFrame()`](../api/UnityEngine.InputSystem.InputAction.html#UnityEngine_InputSystem_InputAction_WasReleasedThisFrame)|True if the level of [actuation](../api/UnityEngine.InputSystem.InputControl.html#UnityEngine_InputSystem_InputControl_EvaluateMagnitude) on the action has, at any point during the current frame, gone from being at or above the [press point](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_defaultButtonPressPoint) to at or below the [release threshold](../api/UnityEngine.InputSystem.InputSettings.html#UnityEngine_InputSystem_InputSettings_buttonReleaseThreshold).|

This example uses three actions called Shield, Teleport and Submit (which are not included in the [default actions]()):
This example uses three actions called Shield, Teleport and Submit (which are not included in the [default actions](ActionsEditor.md#the-default-actions)):

```CSharp
using UnityEngine;
Expand Down Expand Up @@ -101,15 +114,13 @@ public class Example : MonoBehaviour

if (teleportAction.WasPressedThisFrame())
{
// teleport occurs on the first frame that the action was performed, and not again until the button is released
// teleport occurs on the first frame that the action is pressed, and not again until the button is released
}

if (submit.WasReleasedThisFrame())
{
// submit occurs on the frame that the action is released, a common technique for buttons relating to UI controls.
}


}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace UnityEngine.InputSystem.Composites
/// <example>
/// <code>
/// var action = new InputAction();
/// action.AddCompositeBinding("Axis(minValue=0,maxValue=2")
/// action.AddCompositeBinding("Axis(minValue=0,maxValue=2)")
/// .With("Negative", "&lt;Keyboard&gt;/a")
/// .With("Positive", "&lt;Keyboard&gt;/d");
/// </code>
Expand Down Expand Up @@ -73,7 +73,7 @@ public class AxisComposite : InputBindingComposite<float>
/// <example>
/// <code>
/// var action = new InputAction();
/// action.AddCompositeBinding("Axis(minValue=0,maxValue=2")
/// action.AddCompositeBinding("Axis(minValue=0,maxValue=2)")
/// .With("Negative", "&lt;Keyboard&gt;/a")
/// .With("Positive", "&lt;Keyboard&gt;/d");
/// </code>
Expand All @@ -95,7 +95,7 @@ public class AxisComposite : InputBindingComposite<float>
/// <example>
/// <code>
/// var action = new InputAction();
/// action.AddCompositeBinding("Axis(minValue=0,maxValue=2")
/// action.AddCompositeBinding("Axis(minValue=0,maxValue=2)")
/// .With("Negative", "&lt;Keyboard&gt;/a")
/// .With("Positive", "&lt;Keyboard&gt;/d");
/// </code>
Expand Down
Loading