MonoGame icon indicating copy to clipboard operation
MonoGame copied to clipboard

GamePad.SetVibration does not cause vibration on Xbox One controllers until a button is first pressed on the controller

Open vchelaru opened this issue 2 years ago • 4 comments

Note, I was unable to test with the latest develop - I didn't see instructions on how to do so, and when I tried to install through console I got:

error: NU1102: Unable to find package MonoGame.Framework.DesktopGL with version (>= 3.8.1.426-develop)
error:   - Found 11 version(s) in nuget.org [ Nearest version: 3.8.1.303 ]
error:   - Found 0 version(s) in Microsoft Visual Studio Offline Packages
error:   - Found 0 version(s) in C:\Program Files\dotnet\library-packs
error: Package 'MonoGame.Framework.DesktopGL' is incompatible with 'all' frameworks in project 'C:\Users\vchel\Documents\FlatRedBallProjects\TestF\TestF\TestF.csproj'.

If an Xbox360 or Xbox One controller is plugged in, calling SetVibration will not vibrate the controller until input has been detected on the gamepad. If a button is pressed (such as the B button), then SetVibration will properly vibrate the controller. However, if the controller is not touched, and SetVibrate is called, the motor will not vibrate

To test, this code can be added to Game1.cs Update method:

Microsoft.Xna.Framework.Input.GamePad.SetVibration(0, 1, 1);

This has been tested with MonoGame 3.7.1 and the motor does vibrate before any input is detected. This has been tested with three different first and third-party Xbox One wired controllers.

@nkast believes that this bug was introduced between 3.8.0 and 3.8.1, and it may have been this particular issue, but I have not verified:

https://github.com/MonoGame/MonoGame/pull/7690

This has been tested with PS4 controllers and vibration does work in MonoGame 3.8.1 without any input detected.

I do not have access to Switch controllers with a vibrate motor to test.

What version of MonoGame does the bug occur on:

  • MonoGame 3.8.1

What operating system are you using:

  • Windows

What MonoGame platform are you using:

  • DesktopGL

vchelaru avatar May 31 '23 14:05 vchelaru

There may be unused connected GamePad to a computer. I would be upset if a game shook that GamePad off of my desk without acknowledgement. I would be upset.

Is it too much to ask for registration first? Some people prefer keyboard input, even with a GamePad attached.

stromkos avatar Jun 16 '23 20:06 stromkos

@stromkos that should be up to the developer, not MonoGame, to implement. And from a developer's point of view, this is rather unexpected behavior. One would expect that calling a method to do X actually does X, and not "does X if..."

Halofreak1990 avatar Jun 28 '23 17:06 Halofreak1990

EDIT: Deleted my comment. My code was in error and not related to the originally reported issue.

Brett208 avatar Jul 17 '23 01:07 Brett208

@Halofreak1990

... not MonoGame, to implement. And from a developer's point of view, this is rather unexpected behavior.

It was not MonoGame, but Microsoft that made that decision:

The controller registration design was carried over from XNA. Microsoft was extremely picky that the controller with first press was assigned to GamePad state for PlayerIndex.One Second... So on.

The implementation of USB HID instead of fixed controller ports makes the assignment of players' indices random.

One would expect that calling a method to do X actually does X ... If a device has four controllers plugged in without a mapping: calling X says pick a random device and do X, or were you expecting all devices to respond. Both options are arbitrary.

There is simply too much ambiguity and complexity: "What happens on gamepad disconnect and/or reconnect". "My favorite controller was identified as PlayerIndex.Two".

The existing behavior resolves these issues in a consistent and expected manner while removing the minutia.

In DesktopGL, the Joystick interface can be utilized instead of GamePad.

... should be up to the developer... It is completely up to the developer: Make a custom build of monogame or use a C# USB HID wrapper library or Hook directly into SDL.

stromkos avatar Aug 15 '23 20:08 stromkos