Detect desktop vs mobile

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By duke_meister
:warning: Old Version Published before Godot 3 was released.

I thought there would be something in the OS class for this, but what’s a good way of determining whether you’re running on a mobile device vs desktop?

OS.get_name() gives you the name of the operating system, on Windows it returns Windows. However it’s not handy to test if we are on a mobile device or not, so I’m curious to see if there is a better approach too.

Zylann | 2016-05-25 23:41

Thanks, somehow I missed that but I remember seeing it before. For my needs now this will be ok.

duke_meister | 2016-05-25 23:46

:bust_in_silhouette: Reply From: Zylann

OS.get_name() gives you the name of the operating system, it can be one of these:

"Android",
"BlackBerry 10", 
"Flash", 
"Haiku", 
"iOS", 
"HTML5", 
"OSX", 
"Server", 
"Windows", 
"WinRT", 
"X11"

So you have to test if the name corresponds to a mobile platform.
I’m curious to see if there is a better approach too.

Thanks. I’ll wait a while but no doubt this will be the best answer. I guess it’s easy enough to make a global func is_on_mobile() and just check for Android, iOS etc but something in OS would be ‘nice’.

duke_meister | 2016-05-25 23:49

Brilliant, thank you for this.

Robster | 2017-02-12 01:32

:bust_in_silhouette: Reply From: Akien

For mobile vs desktop, Zylann’s answer is likely the most straightforward solution.

If your concern is to know whether controls should be touch-based or mouse and keyboard, you can also use OS.has_touchscreen_ui_hint(), which might (I haven’t tested it) work too for touch-based desktop platforms (e.g. a Linux tablet, or the Windows Surface thingy).

Thanks for the extra info, I was wondering about that function.

duke_meister | 2016-05-26 08:16