Search Unity

Any Decent Instructions On UWP in Unity?

Discussion in 'Windows' started by LW, May 6, 2020.

  1. LW


    Jun 23, 2013
    I can't seem to get any DLLs to work (it's always the Windows.Foundation.UniversalApiContract).

    Not found any clear instructions from MS or Unity on how to access things like Windows.Gaming or use an DLLs I've written.

    None of the forum posts have worked- my guess is, they are outdated because the instructions don't align with Unity's newer options.

    Any direction is appreciated!


    (Also, sad that making tags is prohibited. Perhaps this is why no one can get easy answers when searching...)
  2. timke


    Nov 30, 2017

    To help you out we need more information:

    What exactly are you trying to do or which API do you want to use? Windows.Gaming is just a namespace (not a DLL) that contains several sets of APIs (.Input, .UI, .XboxLiveStorage., etc.).

    What exactly is the problem you're encountering? Is the problem when building your project/app or running it, i.e. compile errors or a runtime exception? Is the problem in Unity Editor or Visual Studio?

    When you say "DLLs I've written", what exactly are they: managed or native? Are you including them in your Unity project (Plugins) or trying referencing them directly from Visual Studio?

    This UWP page covers how to use WinRT APIs (i.e. Windows.Gaming.something) within your scripts:

    This section of the manual covers adding Plugins (DLLs) to your Unity project:

    If the documentation is wrong or missing important details, please provide that feedback via the "Report a problem on this page".
  3. LW


    Jun 23, 2013
    Thanks for the help @timke

    I'm trying to access Input from Windows.Gaming, specifically because I cannot locate the HID Output Report syntax for a racing wheel to control feedback (

    I tried bringing in a managed dll using Windows.Gaming.Input and I encountered that error I mentioned above:
    `Windows.Foundation.UniversalApiContract is missing.`

    I'm wondering if this is even testable in the editor....
  4. timke


    Nov 30, 2017
    Ah..HID *sigh*

    So, let me get this out of the way: using HID on UWP is a nightmare; the WinRT APIs around HID are awful and practically worthless. Microsoft seemed to go out of its way to hide the HID Report data making it very difficult to find the bit/byte offset for a given control.

    So, in your case using the WinRT RacingWheel API might be the best option, since even if you do find the Output Report control offsets for your racing wheel, they probably won't match those on a different device.

    BTW, a set of Input System layouts for various force-feedback devices would be a nice addition to the Asset Store.

    You can invoke WinRT API directly from scripts, however since they won't compile in the Editor you have to enclose them with #ifdef. The WinRT APIs will work when you build/run the actual UWP app.

    So for example:
    Code (CSharp):
    3. var racingWheel = Windows.Gaming.Input.RacingWheel.RacingWheels.FirstOrDefault();
    4. if (racingWheel != null)
    5. {
    6.     if (racingWheel.WheelMotor != null)
    7.     {
    8.         var axes = racingWheel.WheelMotor.SupportedAxes;
    10.         if (Windows.Gaming.Input.ForceFeedback.ForceFeedbackEffectAxes.X == (axes & Windows.Gaming.Input.ForceFeedback.ForceFeedbackEffectAxes.X))
    11.         {
    12.         // Force can be applied through the X axis
    13.         }
    14.     }
    15. }
    16. #endif
    I recommend writing a basic UWP "test app" in Visual Studio to implement the RacingWheel APIs and then port the code into Unity (easier to test this way).