SteamInput implementation


Hi!

As announced, we have added SteamInput to Your Computer Might Be At Risk to give the best experience for our Steam and SteamDeck players.

This process had some frustrating points and we had a hard time finding some documentation, so here is a summary of the most important points.

We use Facepunch.Steamworks as a wrapper for the Steamworks C++ official library. It works, is easy to use and gives a C# style interface.

https://github.com/Facepunch/Facepunch.Steamworks

The latest release doesn't have the SteamUtils call IsRunningOnSteamDeck that allows us to detect SteamDeck and apply some minor tweaks, so we had to compile it from the latest commit.

After some testing, we noticed that sometimes SteamInput worked and sometimes not. We discovered in this bug issue that we have to explicitly initialize the SteamInput interface. 

https://github.com/Facepunch/Facepunch.Steamworks/issues/512

At this point we had the environment ready to compile the wrapper, so we modified it. From that point the process was pretty straightforward, following the Steamworks documentation, but one problem remained: how to test and debug the new features...

SteamInput gets every input from the controller and sends it using the actions that you defined in the actions layout. In order to do that, Steam needs to overlay the program, be in focus, and this program needs to point to the AppId of the game defined in Steamworks.

In order to achieve that with the Unity Editor, you must add its executable to Steam and launch it from there. Now Steam is injected in the editor, but the Unity executable is not the executable of the game with the AppId. You must create a shortcut to Steam with the parameter:

 -forcecontrollerappid <AppID>

Now you can test it and use breakpoints in the debugger!

Another point not currently supported in Facepunch.Steamworks is the rumble. We had to create a method in the SteamInput class to bind the internal method TriggerVibration.

We are using the new Unity InputSystem that receives rumble values as floats [0-1], so the conversion is trivial :

SteamInput.TriggerVibration(c, 

                    (ushort) (leftForce * ushort.MaxValue), 

                    (ushort) (rightForce * ushort.MaxValue));

The last thing that we had to implement in the wrapper was a method to retrieve the PNG icon for the analog actions because the current method only returned images for digital actions.

And that 's all! We hope that it is useful to someone implementing SteamInput in Unity.

One last thing, don't forget to check Your Computer Might Be At Risk on Steam! 🙂

https://store.steampowered.com/app/1969620/

Leave a comment

Log in with itch.io to leave a comment.