Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Application.isMobilePlatform is always returning True for W10

Discussion in 'Windows' started by Wadjey, Mar 9, 2016.

  1. Wadjey

    Wadjey

    Joined:
    Feb 4, 2015
    Posts:
    244
    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
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,644
    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.
     
  3. Wadjey

    Wadjey

    Joined:
    Feb 4, 2015
    Posts:
    244
    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.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,644
    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.
     
    Wadjey likes this.
  5. Wadjey

    Wadjey

    Joined:
    Feb 4, 2015
    Posts:
    244
    Thanks, I'll try this.
    But what's the difference between Application.isMobilePlatform and DeviceType.Handheld ?
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,644
    Not much of the difference really. Just Applicatin.isMbilePlatorm is always true on WSA, while deviceType does some checking for actual device.
     
  7. Wadjey

    Wadjey

    Joined:
    Feb 4, 2015
    Posts:
    244
    Then it's possible to use the checking methods of DeviceType in the Applicatin.isMbilePlatorm to return false when it's a Desktop ;)
     
  8. Sevenate

    Sevenate

    Joined:
    Mar 10, 2016
    Posts:
    16
    Is not Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily should help Unity with appropriate values for Applicatin.isMobilePlatorm?

    This property will return:
    1. Windows.Desktop - for desktops and tablets (with screen larger then 8") and running "Windows 10"
    2. Windows.Mobile - for phones and tablets (with screen size no more then 8") and running "Windows 10 Mobile"
     
  9. IQpierce

    IQpierce

    Joined:
    Jan 24, 2011
    Posts:
    43
    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.
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    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.
     
  11. IQpierce

    IQpierce

    Joined:
    Jan 24, 2011
    Posts:
    43
    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.
     
  12. IQpierce

    IQpierce

    Joined:
    Jan 24, 2011
    Posts:
    43
    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).
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    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.
     
  14. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    The fix for this landed to 2018.1.0b9, 2017.3.1p3 and 2017.2.2p1.
     
  15. Grinning-Pickle

    Grinning-Pickle

    Joined:
    Feb 4, 2013
    Posts:
    7
    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)"