OS
Provides access to common operating system functionalities.
OS.swift:14class OS
This class wraps the most common functionalities for communicating with the host operating system, such as the video driver, delays, environment variables, execution of binaries, command line, etc.
Superclasses
class Object
Base class for all other classes in the engine.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
Type members
static var deltaSmoothing: Bool
If
true
, the engine filters the time delta measured between each frame, and attempts to compensate for random variation. This will only operate on systems where V-Sync is active.static var lowProcessorUsageMode: Bool
If
true
, the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile.static var lowProcessorUsageModeSleepUsec: Int32
The amount of sleeping between frames when the low-processor usage mode is enabled (in microseconds). Higher values will result in lower CPU usage.
static func alert(text: String, title: String
) Displays a modal dialog box using the host OS’ facilities. Execution is blocked until the dialog is closed.
static func closeMidiInputs(
) Shuts down system MIDI driver.
static func crash(message: String
) Crashes the engine (or the editor if called within a
@tool
script). This should only be used for testing the system’s crash handler, not for any other purpose. For general error reporting, use (in order of preference)@GDScript.assert
,@GlobalScope.push_error
oralert(text:title:)
. See alsokill(pid:)
.static func createInstance(arguments: PackedStringArray
) -> Int32 Creates a new instance of Godot that runs independently. The
arguments
are used in the given order and separated by a space.static func createProcess(path: String, arguments: PackedStringArray, openConsole: Bool
) -> Int32 Creates a new process that runs independently of Godot. It will not terminate if Godot terminates. The path specified in
path
must exist and be executable file or macOS .app bundle. Platform path resolution will be used. Thearguments
are used in the given order and separated by a space.static func delayMsec(Int32
) Delays execution of the current thread by
msec
milliseconds.msec
must be greater than or equal to0
. Otherwise,delayMsec(_:)
will do nothing and will print an error message.static func delayUsec(Int32
) Delays execution of the current thread by
usec
microseconds.usec
must be greater than or equal to0
. Otherwise,delayUsec(_:)
will do nothing and will print an error message.static func execute(path: String, arguments: PackedStringArray, output: GArray, readStderr: Bool, openConsole: Bool
) -> Int32 Executes a command. The file specified in
path
must exist and be executable. Platform path resolution will be used. Thearguments
are used in the given order, separated by spaces, and wrapped in quotes. If anoutput
GArray
is provided, the complete shell output of the process will be appended as a singleString
element inoutput
. IfreadStderr
istrue
, the output to the standard error stream will be included too.static func findKeycodeFromString(String
) -> Key Returns the keycode of the given string (e.g. “Escape”).
static func getCacheDir(
) -> String Returns the global cache data directory according to the operating system’s standards. On the Linux/BSD platform, this path can be overridden by setting the
XDG_CACHE_HOME
environment variable before starting the project. See File paths in Godot projects in the documentation for more information. See alsogetConfigDir
andgetDataDir
.static func getCmdlineArgs(
) -> PackedStringArray Returns the command-line arguments passed to the engine.
static func getCmdlineUserArgs(
) -> PackedStringArray Similar to
getCmdlineArgs
, but this returns the user arguments (any argument passed after the double dash--
or double plus++
argument). These are left untouched by Godot for the user.++
can be used in situations where--
is intercepted by another program (such asstartx
).static func getConfigDir(
) -> String Returns the global user configuration directory according to the operating system’s standards. On the Linux/BSD platform, this path can be overridden by setting the
XDG_CONFIG_HOME
environment variable before starting the project. See File paths in Godot projects in the documentation for more information. See alsogetCacheDir
andgetDataDir
.static func getConnectedMidiInputs(
) -> PackedStringArray Returns an array of MIDI device names.
static func getDataDir(
) -> String Returns the global user data directory according to the operating system’s standards. On the Linux/BSD platform, this path can be overridden by setting the
XDG_DATA_HOME
environment variable before starting the project. See File paths in Godot projects in the documentation for more information. See alsogetCacheDir
andgetConfigDir
.static func getDistributionName(
) -> String Returns the name of the distribution for Linux and BSD platforms (e.g. Ubuntu, Manjaro, OpenBSD, etc.).
static func getEnvironment(variable: String
) -> String Returns the value of an environment variable. Returns an empty string if the environment variable doesn’t exist.
static func getExecutablePath(
) -> String Returns the path to the current engine executable.
static func getGrantedPermissions(
) -> PackedStringArray On Android devices: With this function, you can get the list of dangerous permissions that have been granted.
static func getKeycodeString(code: Key
) -> String Returns the given keycode as a string (e.g. Return values:
"Escape"
,"Shift+Escape"
).static func getLocale(
) -> String Returns the host OS locale as a string of the form
language_Script_COUNTRY_VARIANT@extra
. If you want only the language code and not the fully specified locale from the OS, you can usegetLocaleLanguage
.static func getLocaleLanguage(
) -> String Returns the host OS locale’s 2 or 3-letter language code as a string which should be consistent on all platforms. This is equivalent to extracting the
language
part of thegetLocale
string.static func getMainThreadId(
) -> UInt Returns the ID of the main thread. See
getThreadCallerId
.static func getMemoryInfo(
) -> GDictionary Returns the
GDictionary
with the following keys:static func getModelName(
) -> String Returns the model name of the current device.
static func getName(
) -> String Returns the name of the host OS.
static func getProcessId(
) -> Int32 Returns the project’s process ID.
static func getProcessorCount(
) -> Int32 Returns the number of logical CPU cores available on the host machine. On CPUs with HyperThreading enabled, this number will be greater than the number of physical CPU cores.
static func getProcessorName(
) -> String Returns the name of the CPU model on the host machine (e.g. “Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz”).
static func getRestartOnExitArguments(
) -> PackedStringArray Returns the list of command line arguments that will be used when the project automatically restarts using
setRestartOnExit(restart:arguments:)
. See alsoisRestartOnExitSet
.static func getStaticMemoryPeakUsage(
) -> UInt Returns the maximum amount of static memory used (only works in debug).
static func getStaticMemoryUsage(
) -> UInt Returns the amount of static memory being used by the program in bytes (only works in debug).
static func getSystemFontPath(fontName: String, weight: Int32, stretch: Int32, italic: Bool
) -> String Returns path to the system font file with
fontName
and style. Returns empty string if no matching fonts found.static func getSystemFontPathForText(fontName: String, text: String, locale: String, script: String, weight: Int32, stretch: Int32, italic: Bool
) -> PackedStringArray Returns an array of the system substitute font file paths, which are similar to the font with
fontName
and style for the specified text, locale and script. Returns empty array if no matching fonts found.static func getSystemFonts(
) -> PackedStringArray Returns list of font family names available.
static func getThreadCallerId(
) -> UInt Returns the ID of the current thread. This can be used in logs to ease debugging of multi-threaded applications.
static func getUniqueId(
) -> String Returns a string that is unique to the device.
static func getUserDataDir(
) -> String Returns the absolute directory path where user data is written (
user://
).static func getVersion(
) -> String Returns the exact production and build version of the operating system. This is different from the branded version used in marketing. This helps to distinguish between different releases of operating systems, including minor versions, and insider and custom builds.
static func getVideoAdapterDriverInfo(
) -> PackedStringArray Returns the video adapter driver name and version for the user’s currently active graphics card. See also
getVideoAdapterApiVersion
.static func hasEnvironment(variable: String
) -> Bool Returns
true
if the environment variable with the namevariable
exists.static func hasFeature(tagName: String
) -> Bool Returns
true
if the feature for the given feature tag is supported in the currently running instance, depending on the platform, build, etc. Can be used to check whether you’re currently running a debug build, on a certain platform or arch, etc. Refer to the Feature Tags documentation for more details.static func isDebugBuild(
) -> Bool Returns
true
if the Godot binary used to run the project is a debug export template, or when running in the editor.static func isKeycodeUnicode(code: Int64
) -> Bool Returns
true
if the input keycode corresponds to a Unicode character.static func isProcessRunning(pid: Int32
) -> Bool Returns
true
if the child process ID (pid
) is still running orfalse
if it has terminated.static func isRestartOnExitSet(
) -> Bool Returns
true
if the project will automatically restart when it exits for any reason,false
otherwise. See alsosetRestartOnExit(restart:arguments:)
andgetRestartOnExitArguments
.static func isSandboxed(
) -> Bool Returns
true
if application is running in the sandbox.static func isStdoutVerbose(
) -> Bool Returns
true
if the engine was executed with the--verbose
or-v
command line argument, or ifProjectSettings/debug/settings/stdout/verboseStdout
istrue
. See also@GlobalScope.print_verbose
.static func isUserfsPersistent(
) -> Bool If
true
, theuser://
file system is persistent, so that its state is the same after a player quits and starts the game again. Relevant to the Web platform, where this persistence may be unavailable.static func kill(pid: Int32
) -> GodotError Kill (terminate) the process identified by the given process ID (
pid
), e.g. the one returned byexecute(path:arguments:output:readStderr:openConsole:)
in non-blocking mode. See alsocrash(message:)
.static func moveToTrash(path: String
) -> GodotError Moves the file or directory to the system’s recycle bin. See also
remove(path:)
.static func openMidiInputs(
) Initializes the singleton for the system MIDI driver.
static func readStringFromStdin(
) -> String Reads a user input string from the standard input (usually the terminal). This operation is blocking, which causes the window to freeze if
readStringFromStdin
is called on the main thread. The thread callingreadStringFromStdin
will block until the program receives a line break in standard input (usually by the user pressing [kbd]Enter[/kbd]).static func requestPermission(name: String
) -> Bool At the moment this function is only used by
AudioDriverOpenSL
to request permission forRECORD_AUDIO
on Android.static func requestPermissions(
) -> Bool With this function, you can request dangerous permissions since normal permissions are automatically granted at install time in Android applications.
static func revokeGrantedPermissions(
) On macOS (sandboxed applications only), this function clears list of user selected folders accessible to the application.
static func setEnvironment(variable: String, value: String
) Sets the value of the environment variable
variable
tovalue
. The environment variable will be set for the Godot process and any process executed withexecute(path:arguments:output:readStderr:openConsole:)
after runningsetEnvironment(variable:value:)
. The environment variable will not persist to processes run after the Godot process was terminated.static func setRestartOnExit(restart: Bool, arguments: PackedStringArray
) If
restart
istrue
, restarts the project automatically when it is exited withquit(exitCode:)
orNode
notificationWmCloseRequest````. Command linearguments
can be supplied. To restart the project with the same command line arguments as originally used to run the project, passgetCmdlineArgs
as the value for `arguments`.static func setThreadName(String
) -> GodotError Sets the name of the current thread.
static func setUseFileAccessSaveAndSwap(enabled: Bool
) Enables backup saves if
enabled
istrue
.static func shellOpen(uri: String
) -> GodotError Requests the OS to open a resource with the most appropriate program. For example:
static func shellShowInFileManager(fileOrDirPath: String, openFolder: Bool
) -> GodotError Requests the OS to open the file manager, then navigate to the given
fileOrDirPath
and select the target file or folder.static func unsetEnvironment(variable: String
) Removes the environment
variable
from the current environment, if it exists. The environment variable will be removed for the Godot process and any process executed withexecute(path:arguments:output:readStderr:openConsole:)
after runningunsetEnvironment(variable:)
. The removal of the environment variable will not persist to processes run after the Godot process was terminated.class var godotClassName: StringName