DEV Community

Takahiko Inayama
Takahiko Inayama

Posted on

Use InputSystem package for tvOS in Unity 2019.

Use InputSystem package for tvOS in Unity 2019.

If you are trying to build games for tvOS with Unity 2019 with new InputSystem package. You'll see compile error and fails to build.
I found a solution about this.

TL;DR;

Drop a line with com.unity.modules.vr from Packages/manifest.json on your project.

Details

First, create a 3D game project with Unity 2019.3.

Then add InputSystem package.

Alt Text

Switch target platform to tvOS.

Alt Text

You'll see error messages in console when you hit a play button to build.

Alt Text

Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Plugins/XR/TrackedPoseDriver.cs(153,17):
error CS1069: The type name 'XRDevice' could not be found in the namespace 'UnityEngine.XR'. 
Enter fullscreen mode Exit fullscreen mode

It means UnityEngine.XR.XRDevice couldn't be found in XR namespace.

TrackedPoseDriver.cs:153 is looks like this.

        protected virtual void OnDestroy()
        {
#if UNITY_INPUT_SYSTEM_ENABLE_VR
            if (HasStereoCamera())
            {
                UnityEngine.XR.XRDevice.DisableAutoXRCameraTracking(GetComponent<Camera>(), false);
            }
#endif
        }
Enter fullscreen mode Exit fullscreen mode

You may found that UNITY_INPUT_SYSTEM_ENABLE_VR is used in a preprocessor directive in TrackedPoseDriver.cs

And let's take a look at Assembly Definitions of this package.

Packages/com.unity.inputsystem/InputSystem/Unity.InputSystem.asmdef#L45-L47

    "versionDefines": [
        {
            "name": "com.unity.modules.vr",
            "expression": "1.0.0",
            "define": "UNITY_INPUT_SYSTEM_ENABLE_VR"
        },
Enter fullscreen mode Exit fullscreen mode

This says UNITY_INPUT_SYSTEM_ENABLE_VR is set when com.unity.modules.vr:1.0.0 available.

There is no VR support for tvOS yet. So I dropped this without hesitation.

Tada!!

Alt Text

Now I can use InputSystem package.

It's a bit weird solution but works.
This error only happens on tvOS. Maybe available classes are different between platforms even if same com.unity.modules.vr packages are listed in manifest.json.

This article is originally posted on medium.

Top comments (0)