edit: TEN YEARS LATER skaughtx0r redid this, source is on git. Thanks to everyone helping fix this. https://forum.unity.com/threads/force-feedback-for-windows.78268/#post-6670495 Hi, we're working on a vehicle simulator, so one of the things we need is force feedback (eg steering wheels). The Unity input system doesn't have it, so here it is It's a PRO only feature as it's a C++ plugin which uses DirectInput. This is a first successful test but it needs some work. The show stopper at the moment is a crash bug. It's a weird one, where the FIRST time you run it in the Unity editor, it runs fine. You click stop, then if you click play again, Unity will crash. Odd. I presume it's some cleanup issue but I can't find it. Any help would be great. It's a modification of the DirectX June 2010 SDK DirectInput FF sample. ps Unity, can we please get script access to the input system? edit: If you can help go here where we're discussing what the problem might be http://forum.unity3d.com/threads/78580-Force-feedback-plugin?highlight=force+feedback
I have seen your comments on native stereo here: http://feedback.unity3d.com/forums/15792-unity/suggestions/762128-native-stereoscopic-3d-rendering if you are not Cameron Bonde, then sorry. I just have one question have you ever implemented stereoscopic 3d in unity?
Hey, yeah I have. PM me about it. I've done chromadepth and 'normal' passive 3d. Not anaglyph or interlaced or any tricky techniques. BTW, about the force feedback crash, I've got a post over on support since I still need help on it.
I fixed your issue with the plugin. You did not reset the number of axis to zero before enumerating them, so at the second launch, you tried to create the effect with double the axis which are available, leading to E_INVALIDARG. The subsequent call on the uninitialized effect pointer leads to the access violation that crashes Unity. View attachment $FFConst.zip Edit: Btw, you can make a debug build of the plugin, copy that to the Assets folder and then attach the Visual Studio debugger to Unity. You can then set breakpoints in the plugin.
Beautiful! I wasn't looking forward to tracking that down. I'll test it and if it works I'll stick it up on the Asset store for free, not worth charging for I think. Give me a PM with your real name and I'll put a note in the header if you'd like
It really wasn't a big deal, at least with the debugger. Stepping through the code, I noticed the wrong number of axis at the second initialization. I also changed the cooperative mode to background, which should still work for most joysticks and wheels, and the acquisition stays when the window focus is lost. Note in the header is not necessary, but thanks.
Force feedback would make a great addition to the Asset Store. I'm sure many devs will appreciate it.
Hi ! Force feedback work well ! ... the first time ! Vectrex, can you please update the zip with Graealex fix ? I don't know anything about visual studio. Got a 2nd question : - the wheel rotation is 180°, how to have the full 900° of G25/27 ? tks
I patched and recompiled the plugin: View attachment $UnityForceFeedback.zip To get the full 900° rotation with G25/G27 use the Logitech Gaming Software Profiler and use the properties of the steering wheel to set to full range.
If you have problems with the DLL, either download and install "Microsoft Visual C++ 2010 Redistributable Package", or download this static build that doesn't require the MSVCRT libraries. View attachment $UnityForceFeedback_static.zip
move to Unity3.5 today, Test Demo Crash Editor and show this message on my pc: Unity Editor [version: Unity 3.5.0f5_dae8896b94af] UnityForceFeedback.dll caused an Access Violation (0xc0000005) in module UnityForceFeedback.dll at 0023:6a3412d3. graealex, would you like to make this plugin works on Unity 3.5 again ?
Hey guys, I've just tested on: -Windows 7 Ultimate -DX11 -Unity 3.4.0f5 -MS Visual C++ 2010 -Logitech G27 Crashes with the same Access violation as FXCarl received. @FXcarl ever find a solution? @graealex any ideas what the problem causing this is?
Hi, I put the library in my project using unitycar but the force feedback only works on the unity of the game window. When I create the build the force feedback does not work. I'm using the InputManager unitycar. Anyone know if I need to do some special configuration?
It's working fine on both of my steering wheels in the latest version of Unity. The only times it has ever crashed for me is when I run it without the force feedback device plugged in. However, I wish more parameters from the device could be exposed.
ive been messing with this and wondered if anybody is still getting the bug that makes it crash every time the editor is restarted..... thanks. 3.5.3 Pro Windows 7 Ultimate 64 DX9 DX11 Ive tried all three on this page. Thanks Kevin
Good evening, was having the same problem here. Took the sources and recompiled, it fixed the crash in the editor when running the second time and a crash on the game when reloading a scene. Find the dll attached! Let me know if it works for you!! View attachment $UnityForceFeedback.rar
Wow..... much thanks for this...... It fixed it. No crashes anymore. Now i can begin to tweak this FFB without having to restart the editor EVERY time....lol Thanks again. Kevin
i don't get it, when i put in the dll from the first post and the script from there, all works fine, expect the crash after second start. when i try the last dll from "rogeliopuig" it doesnt work and throws an exception "dllNotFound". what i'm doing wrong? @devotid, how you could get it working?
Can someone post a scene exemple to help the community ? I use this to import the dll... Code (CSharp): DllImport ("UnityForceFeedback"); How can I add, for exemple, a left rotation force feedback ? I am working with a thrustmaster T500RS on windows 8.1. Thanks. Jean Roukas
I think what you probably do is use SetDeviceForcesXY(x,y). A negative x value should apply a force in one direction, positive in the other. See the ForceFeedbackTest.cs file in Vectrex's original post. Does anyone have source code for the original dll they could provide? Unity is telling me it wants a 64 bit version of it.
Sorry to bump a really old thread like this, but I thought I'd update with my own progress. I've done a bit of work on the source given by Vectrex and graelex, mostly to stop the thing from crashing. It no longer crashes when there is no Force Feedback device connected, or when one of the functions is called with no Force Feedback device connected. I'm a C# developer, so I suck at C++ so I did this with null checks. I'm not sure if C++ developers are against null checks for some reason, but this was effective. I also got an x86_64 version compiled so it will work on either x86 or x86_64 versions of Windows. It also supports hot-plugging, but I wasn't able to get the plugin to detect when a FF device is UNplugged, so you have to manually call the ResetForceFeedback() function (or do something similar in your own implementation) in order to disable it again. But at least it won't crash. I'll upload my builds along with the source here. If anyone wants to grab it and run with it and add extra features, go right ahead. Essentially, when one of the extern functions returns an int that's less than 0, there's some sort of error. If it's 0 or greater it indicates success. EDIT: You know, I'm pretty sure this thing has a nasty memory leak. Like I said, I suck at C++. I'm gonna have to look into this thing a bit further.
Any progress? I imported your DLL's and noted the leak as well. Would like to use these on a current project, but can roll back to a 32 bit build if need be (and use other FF dll I have on hand).
Same thing here... Huge leak in the profiler with this. I was all excited as it wasnt crashing for a change. I did find something about the Logitech SDK though. If you dont change any settings and only send it forces... ie; Constant or spring force and not change ANY paramaters.... it will not crash each time. I am trying to find the thread that i found it in but have not been successful. When I find it i will report back here.
Found it.... Im going to try to go back to this.... I had this working in 5.3.2 Last week. Ill report back here if I have any luck. http://forum.unity3d.com/threads/unity-editor-crashes-with-native-plugin-on-stop.315884/
I had difficulties with Logitech SDK and a G27 wheel - worked fine on a Driving Force GT - let me know how it goes.
Welllllllll.........I have got it "working" with the Logitech SDK from the Asset store and Unity 5.3.3p1 Im using a Thrustmaster T500r with a leo bodnar box for a old G27 Sequential Shifter setup and another bodnar box running a home made handbrake. I have not tested it yet with my other G27. Im using Rewired Plugin from the asset store with Direct input (Ive tried them ALL and this one is AMAZING action based setup) Problems I have to fix yet: - I have to save the scene EVERYTIME and close/reopen the editor so the Logitech SDK can get the Scene Window ID (Window must be in focus in a standalone or the SDK loses connection.) Shouldnt be a problem in the game as my users have no reason to leave the game until quiting. - Logitech example script only gets the first FFB controller plugged in. ( not really a prob for me as users only use one steering wheel.) I have to make a check of each controller plugged in to see if it has FFB and then find the one that has FFB. Should not be too hard. - I cannot change ANY of the wheel parameters or the editor will insta-crash. (example: Wheel Degrees of rotation, Force Strength, Center Spring... Etc.) I will just have to make my users preset their wheel rotation to max before opening the game. I will then set those in my game with a switch to use "actual cars wheel rotation" or a chosen "shorter lock". Just install the sdk and then place this BAREBONES script on a ForceFeedback controller Gameobject and feed the "force" public variable. My "force" comes directly from the front wheels of my car controller. I do not use any smoothing yet but I will be adding a slider to my game for the users to choose if they want to dampen the forces. THe force is silently clamped by the sdk at -100 and 100 so plan accordingly. Code (csharp): using UnityEngine; using System.Collections; using System.Text; public class LogitechSteeringWheelTEST : MonoBehaviour { public int force; // Use this for initialization void Start () { Debug.Log(LogitechGSDK.LogiSteeringInitialize(false)); } void Update () { //All the test functions are called on the first device plugged in(index = 0) if(LogitechGSDK.LogiUpdate() && LogitechGSDK.LogiIsConnected(0)){ LogitechGSDK.LogiPlayConstantForce(0, force); } } }
Hi, I'm trying to use this dll (UnityForceFeedback) but Unity is throwing a "DllNotFoundException: UnityForceFeedback ForceFeedBack.Update () (at Assets/ForceFeedBack.cs:46)". I have the "ForceFeedBack.dll" in the Assets folder but I tried putting it in the Assets/Plugins/x86 and Assets/Plugins/x64 folders with the same result... I have Windows 7 64-bits and Unity Pro. I would like to know if I have to install another libraries in order to use this plugin. Thanks in advance.
I know, this thread and your post is old. But you have to recompile the DLL for x64. I attached the x64 version. Edit: But the more easier way is to use just the Logitech SDK from Asset Store. Works just fine with other devices than Logitech.
Awesome, I was just looking for 64-bit version of the ffb script for my racing game! Thanks, will try it out!
Are you 100% positive it works with other devices? Because I'm trying to implement it with the Driving Force Pro which is just the previous wheel before the G-Series and I can't get the Logitech script to recognize it. Unity recognizes it as a joystick though and so does Windows. It states its for the G-Series as well so I'm not so sure it works with other devices.
Ive used it with Thrustmaster G500, Logitech G25 G27 G29, Logitech Driving Force GT and fanatec wheels. It works with almost all that I have tried. So I would say "Most". Im not sure about the custom wheels (Leo Bodnar, Neils H etc...) Those I have not tried. Kevin
I've been looking into implementing Force Feedback for my game and found this post. I spent the last few days using the FFConst example and p_025's modifications to Vectrex's code as reference to basically rewrite the DirectInput Force Feedback implementation. It still needs a lot of work, but I got it to the point where Constant Force is working. I tried to make it more generic, currently it only supports one device at a time, but you can now enumerate devices and select the one you want to use. Eventually I want to add support for sending to multiple force feedback devices. I put the code up on github, I'm trying to sort out how to make a UPM package. Feel free to use it or contribute back: https://github.com/skaughtx0r/unity-ffb
Nice thanks. I haven't looked at this thread for 10 years Would be nice to make a plugin for the new Input System.
Unfortunately not, I can try and document things a bit better. In the meantime, I mainly just use it for applying constant force. I just create a GameObject in my main menu that gets set to Don'tDestroyOnLoad. That has the UnityFFB component added to it. Then where I calculate the FFB forces I just set: UnityFFB.instance.force = (int)ffbForce; There's also methods to: Enable: UnityFFB.instance.EnableForceFeedback(); Disable: UnityFFB.instance.DisableForceFeedback(); Start Effects: UnityFFB.instance.StartFFBEffects(); Stop Effects: UnityFFB.instance.StopFFBEffects(); Select Device: UnityFFB.instance.SelectDevice(string deviceGuid); // devices are listed in UnityFFB.instance.devices By default it auto selects the first device and adds a constant force. There is also now another FFB package from MrTimcakes, this was originally forked from my repo, but looks like he completely re-wrote it now. It appears to integrate more closely with the new Unity Input system and has full DirectInput support. I'm not sure if it's documented any better: https://github.com/MrTimcakes/Unity-DirectInput