Skip to content

Unity Native Plugin to expose DirectX DirectInput ForceFeedback

License

Notifications You must be signed in to change notification settings

imDanoush/Unity-DirectInput

 
 

Repository files navigation

Unity DirectInput Force Feedback W/ DInput Manager for Unity!

Now you can manage your DInput devices natively in addition to FFB Support!

image image

Fully integrated with Unity's Input System, Supports any Direct Input Device

Made with Unity GitHub issues open GitHub issues close GitHub package.json version GitHub

Unity-DirectInput Banner

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.

Quick Start

image

Installation

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).

Supported ForceFeedback Effects

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 done, And the collision effects are only in the Unity project.

Compatible Devices

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
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.

Environment

This plugin only works on Windows 8+ 64-bit.

Latest verified Unity version: 2022.2.1f1

Notice

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.

Support

If you have problems, please raise an issue on GitHub.

License

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. Drive icons created by Freepik - Flaticon