Namespace 'Windows' not found in Unity UWP app

2k Views Asked by At

I'm trying to set up a basic UWP project in Unity and use parts of the Windows namespace.* However, no matter which part of the Windows namespace I try to import in my script, I always get

CS0246: The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)

Build support both for Windows and UWP is set up in Visual Studio and Unity and Windows 10 SDK (10.0.19041.0) is installed. Any other ideas how to fix this?

Based on https://forum.unity.com/threads/windows-storage-is-missing-when-building-for-uwp-hololens.541415/ I would have assumed that Windows is available in Unity for UWP as they were able to fix it there?

Thanks


*In the long run, I am trying to use 'Windows.Devices.Input.Preview' to access Gaze Input in a project that also uses Vuforia and thus needs to be UWP. Other tips on how to combine Gaze Tracking and Marker recognition in Unity are also welcome.

1

There are 1 best solutions below

1
On

The Windows namespace in Unity is made for Windows PC build only. It won't work for other systems. On the top of the script try to add a

#if UNITY_STANDALONE_WIN

You should add the whole declaration like

#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
Use SpeechRecognitionEngine class

#endif

If you are building for android or ios you will need also to add:

 #if UNITY_ANDROID  
Use SpeechRecognizer class

#endif

#if UNITY_IOS Use SFSpeechRecognizer class #endif