Skip to content

Instantly share code, notes, and snippets.

@vnavarro
Last active October 16, 2025 12:01
Show Gist options
  • Select an option

  • Save vnavarro/98ad15f5690b7946253322953d03e8ef to your computer and use it in GitHub Desktop.

Select an option

Save vnavarro/98ad15f5690b7946253322953d03e8ef to your computer and use it in GitHub Desktop.
Godot 3 and 4 class with handy verification of mobile platform and version given that platform.
class_name PlatformUtils
extends Object
#OS Possible values are: "Android", "iOS", "HTML5", "OSX", "Server", "Windows", "UWP", "X11".
const OS_ANDROID = "Android"
const OS_IOS = "iOS"
static func isAndroid() -> bool:
return OS.get_name() == OS_ANDROID
static func isIOS() -> bool:
return OS.get_name() == OS_IOS
static func isMobile() -> bool:
return isAndroid() or isIOS()
static func gameVersion() -> String:
if OS.get_name() == "Android":
var export_config: ConfigFile = ConfigFile.new()
var err = export_config.load("res://export_presets.cfg")
if err == OK:
var code = export_config.get_value("preset.1.options", 'version/code')
var version = export_config.get_value("preset.1.options", 'version/name')
var resultVersion = "%s %d" % [version, code]
print(resultVersion)
return resultVersion
else:
print('[engine_root] Error open export_presets.cfgs')
return "undefined"
elif OS.get_name() == "iOS":
var export_config: ConfigFile = ConfigFile.new()
var err = export_config.load("res://export_presets.cfg")
if err == OK:
var version = export_config.get_value("preset.0.options", 'application/version')
print(version)
return version
else:
print('[engine_root] Error open export_presets.cfgs')
return "undefined"
return "beta"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment