[Tutorial] UE4 using Dualshock4 controller (via USB, PS4 DS4 Gamepad)

Edit > Plugins > Add Windows Raw Input.
Edit > Project Settings > Raw Input :

Set Register Default Device True.
Add 1 Device Configurations.
VendorID 0x054C
ProductID 0x05C4
Axis Properties > Inverted True, Offset 0.5.

Edit > Project Settings > Input :
Use Scale 2.0 for each GenericUSBController Axis.

GenericUSBController config/events:

X - Generic USB Button 2
] - Generic USB Button 1
O - Generic USB Button 3
/\ - Generic USB Button 4

L1 - Generic USB Button 5
L2 - Generic USB Button 7 + Axis 8
L3 - Generic USB Button 11

R1 - Generic USB Button 6
R2 - Generic USB Button 8 + Axis 7
R3 - Generic USB Button 12

LStick V - Axis 3
LStick H - Axis 4
RStick V - Axis 1
RStick H - Axis 2

Dpad V - Axis 5
Dpad H - Axis 6

Share - Generic USB Button 9
Options - Generic USB Button 10
PSButton - Generic USB Button 13
TouchPad Click - Generic USB Button 14

10 Likes

Dude this is the best. I was just looking for this information recently but had put it on hold for a moment. This has saved me a nice chunk of time really appreciate it.

2 Likes

I’m glad it’s helpful. I knew some UE4 PC games like CodeVein are able to detect and use DS4 (via USB) successfully, after a few tries with the RawInput plugin it actually did work and it’s not hard to add to the project.

Thank you for this post !
I suppose there is no support for the Force Feedback functions with that type of generic profile ?

I’m glad it’s helpful. Indeed, we don’t have force feedback using the RawInput plugin.

Thanks a thousand times man! Now someone needs to write a plugin that would enable extra functionality like touchpad swipes, gyros, vibro feedback and lightbar.

1 Like

Yeah, that would be great to have, with support for the audio jack too. Sony Playstation is missing a good opportunity to release full driver support for DualShock4 on PCs.

The thing is leaked PS4 SDK from 2017 gives an opportunity to do that already for 2 years.

**NOTICE **- for those who had a second gen Dualshock 4, PID is 0x09CC

Good finding, thanks!

Notice 2

You may notice that after setting up Raw Input with DualShock 4, controls in project will go crazy and will appear unresponsive. This is so because controller is simply sending too much data and Raw Input plugin simply glitching out because of it. You need to filter out this data like this: Imgur: The magic of the Internet . Also, the buttons would took 4 to 6 times to press before anything happens.

there is a fix for this in another thread about RawInput (sorry I don’t have the link). Sadly it caused the d-pad to not function, so maybe not the best fix, but if people want the link I can try to find it again.

D-pad is recognized as another 2 axises - vertical and horizontal. Were the sticks functioning there?

1 Like

The sticks worked fine. I can’t seem to find the thread now, but basically it involved commenting out a line in the rawinput plugin. It 100% fixed the issue you mentioned (data overload, missed button presses, unresponsiveness), and everything was working perfectly. except d-pad would only detect up on the vertical axis, and nothing else.

when I get in front of my computer later, I’ll try to find it again.

Hi, thanks for the post. The big problem I am having is the button presses take way to long to register. You said it was a fix involving commenting out a line, what was it, or do you have the thread where they mentioned a fix?

Does this work on Mac too? I know Catalina is compatible with DS4 via Bluetooth and I do in fact have it properly recognized and connected, but even when I enable the Windows Raw Input plugin, it’s not in Project settings.

I don’t think it will work on Mac, the “Windows Raw” I think means it’s a Windows-only plugin.

Does it work when connecting the controller via Bluetooth or are the inputs going to change?

Man I wish BT connectivity worked as well but looks like RawInput requires a wired connection. Maybe if you alter the plugin it would be.

Hi all. Thanks for your patience. Sincerely sorry for taking so long to get back to you on this. I’ve finally been able to find the post that I was able to use to solve the “unresponsive” button issue:

http://answers.unrealengine.com/questions/583662/index.html

In RawInputWindows.cpp (around line 584 as of UE 4.22):


 [FONT=Helvetica Neue]DeviceButtonData.bPreviousButtonState = DeviceButtonData.bButtonState;
 

is redundant. From what I remember, (this was a long time ago I looked at it), it’s basically creating an infinite loop that continues til interrupted and floods the program with input. By commenting out that line, the inputs all worked perfectly and predictably with the exception of the d-pad.

Perhaps this line of code served some purpose related to the d-pad? My level in C++ is too low to really get it. But hopefully this will help someone more advanced than myself track down a more proper way to fix the issue.