Skip to content

Commit

Permalink
Fix HDRP template input not working when using the new Input System a…
Browse files Browse the repository at this point in the history
…nd no Keyboard/Mouse (Unity-Technologies#6045)

* Fix issues where we were using Keyboard.current and Mouse.current without checking if they were valid.

* Updated changelog

* Missed lines from my fix.

* Update CHANGELOG.md

Co-authored-by: sebastienlagarde <sebastien@unity3d.com>
  • Loading branch information
robinb-u3d and sebastienlagarde committed Oct 18, 2021
1 parent 2a2c2ef commit 3f9a96b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void Start()
// Update is called once per frame
void Update()
{
bool unlockPressed, lockPressed;
bool unlockPressed = false, lockPressed = false;

#if ENABLE_INPUT_SYSTEM
float mouseX = 0, mouseY = 0;
Expand All @@ -36,23 +36,25 @@ void Update()
var delta = Mouse.current.delta.ReadValue() / 15.0f;
mouseX += delta.x;
mouseY += delta.y;
lockPressed = Mouse.current.leftButton.wasPressedThisFrame || Mouse.current.rightButton.wasPressedThisFrame;
}
if (Gamepad.current != null)
{
var value = Gamepad.current.rightStick.ReadValue() * 2;
mouseX += value.x;
mouseY += value.y;
}

unlockPressed = Keyboard.current.escapeKey.wasPressedThisFrame;
lockPressed = Mouse.current.leftButton.wasPressedThisFrame || Mouse.current.rightButton.wasPressedThisFrame;
if (Keyboard.current != null)
{
unlockPressed = Keyboard.current.escapeKey.wasPressedThisFrame;
}

mouseX *= mouseSensitivity * k_MouseSensitivityMultiplier;
mouseY *= mouseSensitivity * k_MouseSensitivityMultiplier;
#else
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * k_MouseSensitivityMultiplier;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * k_MouseSensitivityMultiplier;

unlockPressed = Input.GetKeyDown(KeyCode.Escape);
lockPressed = Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [13.2.0] - 2021-18-10

Version Updated
The version number for this package has increased due to a version update of a related graphics package.
### Fixed
- Fixed new input system codepath not working if you had a controller but no keyboard or mouse.

## [13.1.0] - 2021-09-28

Expand Down

0 comments on commit 3f9a96b

Please sign in to comment.