+6 votes

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?

in Engine by (722 points)

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.

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

2 Answers

+14 votes
Best answer

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.

by (28,982 points)
selected by

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 isonmobile() and just check for Android, iOS etc but something in OS would be 'nice'.

Brilliant, thank you for this.

+7 votes

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).

by (1,953 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.