This package allows you to easily integrate both the input and ForceFeedback features of DirectX DirectInput from within Unity. This allows you to interface with HID peripherals with ForceFeedback capabilities. This can be used to build vivid simulated experiences.
The package will create a virtual device inside Unity's Input System. This device can then be used like any other device inside the Input System, allowing for easy rebinding. ForceFeedback capabilities can be accessed via the DIManager class. The DirectInputExplorer is a Windows forms application built in parallel with the C++ library to enable quick development by avoiding the need to reload Unity after every change. It also functions as an easy way to examine DirectInput devices.
This package requires the use of Unity's new Input System, to ensure com.unity.inputsystem is installed in the project. Install it via the package manager via:
Window -> Package Manager => Input System
Next, Go to the Releases section of this GitHub repository to directly download and install the plugin with all the samples and examples, Or copy and paste the Plugin folder of this repository into the Assets folder of your Unity project and import its own Unitypackage example demo file. If Unity is opened, restart it to import the DLL file properly. The folders that end with the ~
character are automatically skipped by Unity and are used for writing the DLL file as well as the ForceFeedBack Windows App software (which you can find in ./DirectInputExplorer~\DirectInputExplorer\bin\Debug\net5.0-windows
).
Effect | Stat |
---|---|
ConstantForce | ✅ |
Damper | ✅ |
Friction | ✅ |
Inertia | ✅ |
RampForce | ✅ |
SawtoothDown | ✅ |
SawtoothUp | ✅ |
Sine | ✅ |
Spring | ✅ |
Square | ✅ |
Triangle | ✅ |
CustomForce | ℹ️ |
Front Collision | ✅ |
Rear Collision | ✅ |
Left Collision | ✅ |
RightCollision | ✅ |
Note that everything is adjustable in the native DLL, The Custom Force effect exists but has not been fully implemented, And the collision effects are only in the Unity project. This is optimized to be used in Unity Game Engine only.
Note that all the devices that use Direct Input (from the old Logitech G wheels to the advanced Simucube ones) should work
The community has tested and verified these devices do indeed work. Albeit not all devices support all the FFB effects!
Peripheral | Test Status |
---|---|
Simucube Ultimate 2 | ✅ Verified |
Fanatec CSL DD (Both PC & Comp mode + 8NM Kit) | ✅ Verified |
Fanatec CSL Elite | ✅ Verified |
Fanatec CSW V2.0 | ✅ Verified |
Fanatec WRC Wheel Rim | ✅ Verified |
Fanatec Formula V2 Wheel Rim & APM | ✅ Verified |
Fanatec CSL LC Pedals | ✅ Verified |
Fanatec ClubSport Pedals V1 | ✅ Verified |
Fanatec ClubSport Pedals V3 | ✅ Verified |
Fanatec ClubSport Shifter SQ V 1.5 | ✅ Verified |
Logitech G29 / G920 | ✅ Verified |
Moza R9 | ✅ Verified |
PRO Racing Wheel | ✅ Verified |
Simagic Alpha-Mini | ✅ Verified |
Thrustmaster TX | ✅ Verified |
Note for pedals, only input readings were guaranteed to likely work fine.
- Latest verified Unity version: 2022.3
The DirectInputManager should run on Windows 10 22H2 and newer (e.g. Windows 11) out of the box. The DirectInput API is available on these modern Windows versions without additional packages.
For developers working on the project:
- Visual Studio 2019 or newer
- .NET 5 SDK
- Windows SDK (for DirectInput headers)
- Microsoft Visual C++ Redistributable
- C++ build tools if modifying the native DLL You may need to enable "allow unsafe code" in the Player Settings of your Unity project to build your game, or not - not tested.
For end users running the built application:
- Microsoft Visual C++ Redistributable
- .NET 5 Runtime
- Windows 10 22H2 or newer (Can be used in Windows 7+ theoretically but not tested)
- The DirectInputForceFeedback.dll must be properly deployed alongside the application
- No special DirectX installation is required on modern Windows as DirectInput is part of the OS The project provides force feedback support for DirectInput-compatible devices like joysticks, wheels, and game controllers. It's designed to work both as a standalone .NET application and within Unity projects.
For Unitypackage, if you do not have some SDKs installed you may get an error stating that the DLL is not found, to solve that issue do the following:
- Clone the DirectInput repository ,
- then go to the
/DirectInputForcefeedback~
folder, there is a.sln
Visual Studio project file,- open it and press F5 in VS to build a new DLL where you'll be asked to install the missing SDKs
- the newly built DLL will be available in the directory where the
output
of the visual studio states. Simply copy it from where it was created, and paste it over the DLL in Unity'sAsset/Plugin
folder for Direct Input
Occasionally calls to EnumerateDevices will take orders of magnitude longer than usual to execute (up to 60 seconds), this is caused by a Windows bug attempting to load an absent hardware device. USB Audio DACs & Corsair keyboards are known the cause this issue, try disconnecting and reconnecting offending USB devices. For more information see this StackOverflow post about the issue from 2012. See issue #1 for more info.
The original fundamentals coded by Mr.TimCakes though got significantly changed.
This project is free Open-Source software released under the LGPL-3.0 License. Further information can be found under the terms specified in the license.