Application.isMobilePlatform is always returning True for W10

Hi,
When I build a Windows Universal 10 app and run it on a PC, Application.isMobilePlatform is returning True.
On PC I think Application.isMobilePlatform must return False.
Case number: 778250

Actually it’s by design. Phones and tablets are mobile platforms and it’s close to impossible ato differentiate between desktop or tablet on WSA, hence the whole platform is reporated to be mobile.

Thanks for your response Aurimas,
Microsoft should provide a way to identify if it’s a mobile platform or desktop platform for the W10 UWP, this is very important for developers to adapt the UX of their games when it’s played on Desktop or Mobile.
For Desktop the UI and UX must be adapted to Desktop environment (screen further from user, the game is played using mice and keyboard…).
For Mobile the UI and UX must be adapted to Mobile environment (screen closer to user, touch screen…).
I hope you will see more deeply into this issue and try to find a solution.

You can use SystemInfo.deviceType, it will be Handheld on Windows Phone, but Desktop elsewhere.
Tablet vs. Desktop is trickier. Input.touchSupported and Input.mousePresent are close to telling that, but not guaranteed, as well as tablet can change it’s mode/type at any time.

1 Like

Thanks, I’ll try this.
But what’s the difference between Application.isMobilePlatform and DeviceType.Handheld ?

Not much of the difference really. Just Applicatin.isMbilePlatorm is always true on WSA, while deviceType does some checking for actual device.

Then it’s possible to use the checking methods of DeviceType in the Applicatin.isMbilePlatorm to return false when it’s a Desktop :wink:

Is not Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily should help Unity with appropriate values for Applicatin.isMobilePlatorm?

This property will return:

  • Windows.Desktop - for desktops and tablets (with screen larger then 8") and running “Windows 10”
  • Windows.Mobile - for phones and tablets (with screen size no more then 8") and running “Windows 10 Mobile”

Application.isMobilePlatform returns true whenever my UWP app is running on the XboxOne platform. XboxOne is not a mobile platform.

A Unity dev pasted above an alternate way to determine whether I am running on a mobile platform in this situation, but with no indication that the behavior of the isMobilePlatform flag was going to be changed.

Can a Unity dev please explain why this is not a bug?

Application.isMobilePlatform is a convenience method that my team has used in dozens of scripts to enable optional functionality only while on mobile devices. Unity seems to be saying that recommended solution to this problem is to not rely on this convenience method at all on the UWP platform, and to add a workaround to all of our scripts that check this flag, since 100% of them are guaranteed to produce bugs (since the only reason to check the flag is to enable functionality that’s only appropriate for mobile platforms, which we never want when running on XboxOne). After copying/pasting this fix into all those scripts, my team would also be required to remember in all future scripts that they write that this flag cannot be trusted on this platform, and to copy/paste the same workaround to all of these cases.

This convenience method is not proving to be very convenient. If this flag can’t return something meaningful on this platform, I would strongly suggest deprecating the flag entirely, so that other teams don’t make the mistake of believing they can rely on it to determine what kind of platform they’re on reliably in a cross-platform development paradigm.

The reason for that is because the definition for mobile platform is not clear. Is a phone mobile device? That’s easy, it is. What about a laptop? You could say no. What about a tablet? That’s a yes? What about surface laptop which is half laptop half tablet? What about HoloLens or Raspberry Pi?

What exactly are you trying to check for when you mean “mobile platform”? Touchscreen? Whether you’re on battery? Whether the hardware is weak? On UWP they all overlap and there’s no simple binary answer.

On UWP I believe almost any developer would expect for isMobilePlatform to return TRUE when the app is running on a mobile phone device (Windows Phone); and FALSE when running on any non-mobile-phone device.

This may not be technically correct given that UWP is elsewhere treated as a single “platform”. But this flag is useful for enabling mobile-phone-specific functionality, and it would be very helpful for Unity to maintain that functionality.

A Unity developer above recommended pasting exactly that kind of check in all places where a developer would query isMobilePlatform. Another developer above asked why Unity doesn’t make this behavior the default behavior of isMobilePlatform on UWP. I am (again) asking the same question.

However, even if this change is made, it probably would not appear in time to help my project’s needs and timeline.

We are compiling for UWP on IL2CPP. I have found that there is an undocumented method in C++ code called “il2cpp_add_internal_call” which can be used to override any Unity engine method call and point it to another custom method. I did a brief test of using this method in a native plugin (.cpp file) in order to use this to remap “Debug.LogError”, but I did not see the LogError functionality change when I ran the game.

Could a Unity dev advise on whether this is a reasonable thing to do, and if so how to get it working? If it can be applied to properties, it would perfectly fit our needs to make isMobilePlatform meaningful on UWP.

To answer your other question, most of our script seem to use this flag to enable functionality appropriate for low-spec (weak CPU/GPU and low memory) devices; or to enable functionality for devices with a primarily touch interface.

It’s true that it would be more appropriate to check those limitations more explicitly. I agree that the definition of “mobile” is fuzzy, and becoming fuzzier with each new platform released (e.g. Switch).

Having a single check of whether the game is running on a mobile phone/tablet device has been useful. If we shouldn’t rely on this check anymore, please deprecate the flag and let us know how we should perform such a check instead (or whether we need to write our own API for answering such questions and handling Unity’s various quirks such as this one).

I wouldn’t advice on hacking il2cpp internal machinery. Those will be prone to breaking, they are also easy to get wrong and get memory corruptions down the line. But yes, it can be applied to properties, but you’ll have to step through generated source code to find out how.

The fix for this landed to 2018.1.0b9, 2017.3.1p3 and 2017.2.2p1.

Would be nice to know what the fix is…

Edit: https://unity3d.com/unity/beta/unity2018.1.0b9

“Universal Windows Platform: Fixed Application.isMobilePlatform results to be consistent with SystemInfo.deviceType and updated the API docs for these APIs. (991466)”