Getting DualShock Controllers To Work Natively On PC Is Harder Than You'd Think

This week marks the launch the twin-stick bullet hell shooter Assault Android Cactus, one of the highest profile Australian games right now. It's been a star ever since it debuted at AVCon and PAX Australia two years ago, and has continued to make waves at shows internationally.

One of the game's cooler features is it's native support for DualShock 4 controllers, something of a rarity (still) on PC. I spoke to Witch Beam's programmer and animator Tim Dawson about the challenge of implementing native DS4 support, and why more studios haven't done it.

"When the PlayStation 4 was released and the Dual Shock 4 came with native Windows support, it seemed like a natural fit to get [Assault Android] Cactus playable with it," Dawson told me. "There's always been ways to get other controllers to connect with Windows but because they often use third party drives and workarounds, I figured the onerous was on the user to set them up so they would work like an Xbox 360 pad, since that is the de facto PC controller but since you could plug a Dual Shock 4 into a PC and it would show up as a controller, I wanted that to 'just work'."

Problem is, it doesn't just work. While you can plug the DS4 into a PC with any USB to micro-USB cable and have it appear as a controller, it only shows up as a Direct Input device. Those don't map the same way as Xbox 360 controllers and given that most games only support XInput, the API for 360 and "next generation" controllers, DS4 pads are left out in the cold.

Assault Android Cactus and Witch Beam had another issue with native support too: the Unity engine itself. "For a Unity developer, the problem is the [DS4] will be readable just fine, but it's buttons and axis are all mismatched compared to a 360 controller."

"It ended up as a lot of tangled code that would try its best to detect when a Dual Shock 4 was being used, and read it differently, and hope for the best. At one point you could plug 4 DS4's in and play Cactus that way, or use 4 Xbox controllers, but not mix and match, and if you added an older Logitech controller into the mix, it was anyone's guess what would happen."

When the studio upgraded to Unity 5, Dawson's will to find a solution on his own eventually broke and he began searching out for middleware solutions. "The main thing is Unity doesn't give enough access to hardware to really sort out what's happening in meat space," he explained, adding that the upgrade to Unity 5 allowed developers to access the names of devices albeit with one significant caveat.

"You can access the names of devices but they won't necessarily correspond to the controller your accessing. They mostly will, but when it goes wrong, it goes really wrong — users will suddenly have backwards controls and trigger will make them move forwards."

After much frustration, Dawson ended up settling on an input system called Rewired available on the Unity store. It's a framework that builds on Unity's basic out-of-the-box controller support and adds compatibility for hot swappable joysticks, over 20 buttons per controller and, importantly, the removal of having to track joystick IDs (resolving the issue Dawson mentioned earlier about accessing the names of devices).

I asked why more studios, whether they were using Unity or not, didn't implement native support for DS4 controllers. You'd think it would make sense, considering the PS4's popularity over the Xbox One. The Queenslander suggested it was probably out of pragmatism, and that the proliferation — and support for the 360 controller — fostered an expectation among developers that made it easier to shift the problem onto users.

"I think the main problem is that unless you have these devices sitting on your desk and are testing them regularly it's easy to forget they exist or know what they'll even do when plugged in," he told me.

"I suppose the issue is all on the PC side; identifying inputs accurately is a deceptively hard problem in modern engines like Unity, workarounds are imperfect, so you can be blamed by users for even trying, and it can feel like it's of dubious benefit, which makes it feel like a luxury. On Sony's side, they tried to keep things simple by making the Dual Shock 4 connect as a basic PC gamepad when connected to a computer, which is great, but the downside is that's all the computer sees it as, which rules out using the speaker, light, touch pad, tilt sensors or even the rumble, unless you're using your own drivers."

For those who want to use the other features of the DS4 on their PC, third-party drivers like DS4Windows are a godsend. They don't always work with newer versions of Windows, however; I had immense problems getting anything beyond basic support for Windows 8.1, although I've had no issues with DS4Windows (and other wrappers) on Windows 7 and Windows 10.

If you're interested in testing the efforts of Dawson's labour, you can try a demo of Assault Android Cactus on Steam now. The game is on sale for US$12 as part of a launch discount, which isn't a bad asking price for something with a 98% user rating from nearly 300 reviews.


Comments

    I was really happy to see that Mad Max has support for DS4s out the gate, which was a nice touch from the devs. I'm used to the pain of mismapping on the DS4, since if you were running certain programs (Steam caused slight issues, Teamspeak was an utter nightmare) then there were compatibility issues with the way the DS4 XInput mapper would take preferential control of things (was resolved in Windows 8, but a big problem for Windows 7).

    Still, point is, it's nice when a dev deals with it, even if it is a pain for them.

    How come 360 controllers work easier?

      Windows based games can use various API's to handle controllers. The most commonly used on Windows games are DirectInput and XInput. As you'd expect from their names, DirectInput is part of DirectX and provides a generic interface, so pretty much all controllers (including steering wheels, joysticks etc) are supported. If you have low level access to DirectInput and windows subsystems, you can support pretty much anything, but it's "messy" if you like. You have to do a fair bit of controller specific code for each controller, because of things like button maps, triggers, analog sticks can all be differently presented to the API, causing results mentioned in the article (triggers causing the player to move foward etc).

      XInput is a windows port of the Xbox input system. It's cleaner than DirectInput, because XInput only handles xbox controller format (or devices that implement that interface). All devices that are XInput compatible handle in the same way, so not much controller specific code needs to be added.

      It's possible to use both of them together at the same time, but it does have some quirks.

    I have used a third party driver from Scarlett Crush Productions with my DS3 controller and it works perfectly through USB and bluetooth and it works with DS4 as well.

    The only problem is that you need to dedicate a bluetooth dongle though.

    The DS3 was a nightmare. The DS4 is plug n' play , but vibration won't work, and also a breeze - http://ds4windows.com/

    Yeah, I hate the direct input mapper. Square being button 1 makes no sense to me and the lack of vibrations disturbs me

Join the discussion!

Trending Stories Right Now