Class OS
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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.
Note: In Godot 4, OS functions related to window management were moved to the DisplayServer singleton.
public static class OS
- Inheritance
-
OS
- Inherited Members
Properties
DeltaSmoothing
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.
public static bool DeltaSmoothing { get; set; }
Property Value
LowProcessorUsageMode
If true
, the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile.
public static bool LowProcessorUsageMode { get; set; }
Property Value
LowProcessorUsageModeSleepUsec
The amount of sleeping between frames when the low-processor usage mode is enabled (in microseconds). Higher values will result in lower CPU usage.
public static int LowProcessorUsageModeSleepUsec { get; set; }
Property Value
Singleton
public static OSInstance Singleton { get; }
Property Value
Methods
Alert(string, string)
Displays a modal dialog box using the host OS' facilities. Execution is blocked until the dialog is closed.
public static void Alert(string text, string title = "Alert!")
Parameters
CloseMidiInputs()
Shuts down system MIDI driver.
Note: This method is implemented on Linux, macOS and Windows.
public static void CloseMidiInputs()
Crash(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
or Alert(string, string). See also Kill(int).
public static void Crash(string message)
Parameters
message
string
CreateInstance(string[])
Creates a new instance of Godot that runs independently. The arguments
are used in the given order and separated by a space.
If the process creation succeeds, the method will return the new process ID, which you can use to monitor the process (and potentially terminate it with Kill(int)). If the process creation fails, the method will return -1
.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static int CreateInstance(string[] arguments)
Parameters
arguments
string[]
Returns
CreateProcess(string, string[], bool)
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. The arguments
are used in the given order and separated by a space.
On Windows, if openConsole
is true
and the process is a console app, a new terminal window will be opened. This is ignored on other platforms.
If the process creation succeeds, the method will return the new process ID, which you can use to monitor the process (and potentially terminate it with Kill(int)). If the process creation fails, the method will return -1
.
For example, running another instance of the project:
var pid = OS.CreateProcess(OS.GetExecutablePath(), new string[] {});
See Execute(string, string[], Array, bool, bool) if you wish to run an external command and retrieve the results.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
Note: On macOS, sandboxed applications are limited to run only embedded helper executables, specified during export or system .app bundle, system .app bundles will ignore arguments.
public static int CreateProcess(string path, string[] arguments, bool openConsole = false)
Parameters
Returns
DelayMsec(int)
Delays execution of the current thread by msec
milliseconds. msec
must be greater than or equal to 0
. Otherwise, DelayMsec(int) will do nothing and will print an error message.
Note:
DelayMsec(int) is a blocking way to delay code execution. To delay code execution in a non-blocking way, see CreateTimer(double, bool, bool, bool). Awaiting with CreateTimer(double, bool, bool, bool) will delay the execution of code placed below the await
without affecting the rest of the project (or editor, for EditorPlugin
s and EditorScript
s).
Note: When DelayMsec(int) is called on the main thread, it will freeze the project and will prevent it from redrawing and registering input until the delay has passed. When using DelayMsec(int) as part of an EditorPlugin
or EditorScript
, it will freeze the editor but won't freeze the project if it is currently running (since the project is an independent child process).
public static void DelayMsec(int msec)
Parameters
msec
int
DelayUsec(int)
Delays execution of the current thread by usec
microseconds. usec
must be greater than or equal to 0
. Otherwise, DelayUsec(int) will do nothing and will print an error message.
Note:
DelayUsec(int) is a blocking way to delay code execution. To delay code execution in a non-blocking way, see CreateTimer(double, bool, bool, bool). Awaiting with CreateTimer(double, bool, bool, bool) will delay the execution of code placed below the await
without affecting the rest of the project (or editor, for EditorPlugin
s and EditorScript
s).
Note: When DelayUsec(int) is called on the main thread, it will freeze the project and will prevent it from redrawing and registering input until the delay has passed. When using DelayUsec(int) as part of an EditorPlugin
or EditorScript
, it will freeze the editor but won't freeze the project if it is currently running (since the project is an independent child process).
public static void DelayUsec(int usec)
Parameters
usec
int
Execute(string, string[], Array, bool, bool)
Executes a command. The file specified in path
must exist and be executable. Platform path resolution will be used. The arguments
are used in the given order, separated by spaces, and wrapped in quotes. If an output
Array is provided, the complete shell output of the process will be appended as a single string element in output
. If readStderr
is true
, the output to the standard error stream will be included too.
On Windows, if openConsole
is true
and the process is a console app, a new terminal window will be opened. This is ignored on other platforms.
If the command is successfully executed, the method will return the exit code of the command, or -1
if it fails.
Note: The Godot thread will pause its execution until the executed command terminates. Use GodotThread to create a separate thread that will not pause the Godot thread, or use CreateProcess(string, string[], bool) to create a completely independent process.
For example, to retrieve a list of the working directory's contents:
var output = new Godot.Collections.Array();
int exitCode = OS.Execute("ls", new string[] {"-l", "/tmp"}, output);
If you wish to access a shell built-in or execute a composite command, a platform-specific shell can be invoked. For example:
var output = new Godot.Collections.Array();
OS.Execute("CMD.exe", new string[] {"/C", "cd %TEMP% && dir"}, output);
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
Note: To execute a Windows command interpreter built-in command, specify cmd.exe
in path
, /c
as the first argument, and the desired command as the second argument.
Note: To execute a PowerShell built-in command, specify powershell.exe
in path
, -Command
as the first argument, and the desired command as the second argument.
Note: To execute a Unix shell built-in command, specify shell executable name in path
, -c
as the first argument, and the desired command as the second argument.
Note: On macOS, sandboxed applications are limited to run only embedded helper executables, specified during export.
Note: On Android, system commands such as dumpsys
can only be run on a rooted device.
public static int Execute(string path, string[] arguments, Array output = null, bool readStderr = false, bool openConsole = false)
Parameters
Returns
FindKeycodeFromString(string)
Returns the keycode of the given string (e.g. "Escape").
public static Key FindKeycodeFromString(string @string)
Parameters
string
string
Returns
GetCacheDir()
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 also GetConfigDir() and GetDataDir().
Not to be confused with GetUserDataDir(), which returns the project-specific user data path.
public static string GetCacheDir()
Returns
GetCmdlineArgs()
Returns the command-line arguments passed to the engine.
Command-line arguments can be written in any form, including both --key value
and --key=value
forms so they can be properly parsed, as long as custom command-line arguments do not conflict with engine arguments.
You can also incorporate environment variables using the GetEnvironment(string) method.
You can set ProjectSettings.editor/run/main_run_args
to define command-line arguments to be passed by the editor when running the project.
Here's a minimal example on how to parse command-line arguments into a dictionary using the --key=value
form for arguments:
var arguments = new Godot.Collections.Dictionary();
foreach (var argument in OS.GetCmdlineArgs())
{
if (argument.Find("=") > -1)
{
string[] keyValue = argument.Split("=");
arguments[keyValue[0].LStrip("--")] = keyValue[1];
}
else
{
// Options without an argument will be present in the dictionary,
// with the value set to an empty string.
arguments[keyValue[0].LStrip("--")] = "";
}
}
Note: Passing custom user arguments directly is not recommended, as the engine may discard or modify them. Instead, the best way is to use the standard UNIX double dash (--
) and then pass custom arguments, which the engine itself will ignore. These can be read via GetCmdlineUserArgs().
public static string[] GetCmdlineArgs()
Returns
- string[]
GetCmdlineUserArgs()
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 as startx
).
For example, in the command line below, --fullscreen
will not be returned in GetCmdlineUserArgs() and --level 1
will only be returned in GetCmdlineUserArgs():
# Godot has been executed with the following command:
# godot --fullscreen -- --level=2 --hardcore
OS.get_cmdline_args() # Returns ["--fullscreen", "--level=2", "--hardcore"]
OS.get_cmdline_user_args() # Returns ["--level=2", "--hardcore"]
public static string[] GetCmdlineUserArgs()
Returns
- string[]
GetConfigDir()
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 also GetCacheDir() and GetDataDir().
Not to be confused with GetUserDataDir(), which returns the project-specific user data path.
public static string GetConfigDir()
Returns
GetConnectedMidiInputs()
Returns an array of MIDI device names.
The returned array will be empty if the system MIDI driver has not previously been initialized with OpenMidiInputs().
Note: This method is implemented on Linux, macOS and Windows.
public static string[] GetConnectedMidiInputs()
Returns
- string[]
GetDataDir()
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 also GetCacheDir() and GetConfigDir().
Not to be confused with GetUserDataDir(), which returns the project-specific user data path.
public static string GetDataDir()
Returns
GetDistributionName()
Returns the name of the distribution for Linux and BSD platforms (e.g. Ubuntu, Manjaro, OpenBSD, etc.).
Returns the same value as GetName() for stock Android ROMs, but attempts to return the custom ROM name for popular Android derivatives such as LineageOS.
Returns the same value as GetName() for other platforms.
Note: This method is not supported on the web platform. It returns an empty string.
public static string GetDistributionName()
Returns
GetEnvironment(string)
Returns the value of an environment variable. Returns an empty string if the environment variable doesn't exist.
Note: Double-check the casing of variable
. Environment variable names are case-sensitive on all platforms except Windows.
public static string GetEnvironment(string variable)
Parameters
variable
string
Returns
GetExecutablePath()
Returns the path to the current engine executable.
Note: On macOS, always use CreateInstance(string[]) instead of relying on executable path.
public static string GetExecutablePath()
Returns
GetGrantedPermissions()
On Android devices: With this function, you can get the list of dangerous permissions that have been granted.
On macOS (sandboxed applications only): This function returns the list of user selected folders accessible to the application. Use native file dialog to request folder access permission.
public static string[] GetGrantedPermissions()
Returns
- string[]
GetKeycodeString(Key)
Returns the given keycode as a string (e.g. Return values: "Escape"
, "Shift+Escape"
).
See also Keycode and GetKeycodeWithModifiers().
public static string GetKeycodeString(Key code)
Parameters
code
Key
Returns
GetLocale()
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 use GetLocaleLanguage().
language
- 2 or 3-letter language code, in lower case.
Script
- optional, 4-letter script code, in title case.
COUNTRY
- optional, 2 or 3-letter country code, in upper case.
VARIANT
- optional, language variant, region and sort order. Variant can have any number of underscored keywords.
extra
- optional, semicolon separated list of additional key words. Currency, calendar, sort order and numbering system information.
public static string GetLocale()
Returns
GetLocaleLanguage()
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 the GetLocale() string.
This can be used to narrow down fully specified locale strings to only the "common" language code, when you don't need the additional information about country code or variants. For example, for a French Canadian user with fr_CA
locale, this would return fr
.
public static string GetLocaleLanguage()
Returns
GetMainThreadId()
Returns the ID of the main thread. See GetThreadCallerId().
Note: Thread IDs are not deterministic and may be reused across application restarts.
public static ulong GetMainThreadId()
Returns
GetMemoryInfo()
Returns the Dictionary with the following keys:
"physical"
- total amount of usable physical memory, in bytes or -1
if unknown. This value can be slightly less than the actual physical memory amount, since it does not include memory reserved by kernel and devices.
"free"
- amount of physical memory, that can be immediately allocated without disk access or other costly operation, in bytes or -1
if unknown. The process might be able to allocate more physical memory, but such allocation will require moving inactive pages to disk and can take some time.
"available"
- amount of memory, that can be allocated without extending the swap file(s), in bytes or -1
if unknown. This value include both physical memory and swap.
"stack"
- size of the current thread stack, in bytes or -1
if unknown.
public static Dictionary GetMemoryInfo()
Returns
GetModelName()
Returns the model name of the current device.
Note: This method is implemented on Android and iOS. Returns "GenericDevice"
on unsupported platforms.
public static string GetModelName()
Returns
GetName()
Returns the name of the host OS.
On Windows, this is "Windows"
.
On macOS, this is "macOS"
.
On Linux-based operating systems, this is "Linux"
.
On BSD-based operating systems, this is "FreeBSD"
, "NetBSD"
, "OpenBSD"
, or "BSD"
as a fallback.
On Android, this is "Android"
.
On iOS, this is "iOS"
.
On the web, this is "Web"
.
Note: Custom builds of the engine may support additional platforms, such as consoles, yielding other return values.
switch (OS.GetName())
{
case "Windows":
GD.Print("Windows");
break;
case "macOS":
GD.Print("macOS");
break;
case "Linux":
case "FreeBSD":
case "NetBSD":
case "OpenBSD":
case "BSD":
GD.Print("Linux/BSD");
break;
case "Android":
GD.Print("Android");
break;
case "iOS":
GD.Print("iOS");
break;
case "Web":
GD.Print("Web");
break;
}
public static string GetName()
Returns
GetProcessId()
Returns the project's process ID.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static int GetProcessId()
Returns
GetProcessorCount()
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.
public static int GetProcessorCount()
Returns
GetProcessorName()
Returns the name of the CPU model on the host machine (e.g. "Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz").
Note: This method is only implemented on Windows, macOS, Linux and iOS. On Android and Web, GetProcessorName() returns an empty string.
public static string GetProcessorName()
Returns
GetRestartOnExitArguments()
Returns the list of command line arguments that will be used when the project automatically restarts using SetRestartOnExit(bool, string[]). See also IsRestartOnExitSet().
public static string[] GetRestartOnExitArguments()
Returns
- string[]
GetStaticMemoryPeakUsage()
Returns the maximum amount of static memory used (only works in debug).
public static ulong GetStaticMemoryPeakUsage()
Returns
GetStaticMemoryUsage()
Returns the amount of static memory being used by the program in bytes (only works in debug).
public static ulong GetStaticMemoryUsage()
Returns
GetSystemDir(SystemDir, bool)
Returns the actual path to commonly used folders across different platforms. Available locations are specified in OS.SystemDir.
Note: This method is implemented on Android, Linux, macOS and Windows.
Note: Shared storage is implemented on Android and allows to differentiate between app specific and shared directories. Shared directories have additional restrictions on Android.
public static string GetSystemDir(OS.SystemDir dir, bool sharedStorage = true)
Parameters
Returns
GetSystemFontPath(string, int, int, bool)
Returns path to the system font file with fontName
and style. Returns empty string if no matching fonts found.
The following aliases can be used to request default fonts: "sans-serif", "serif", "monospace", "cursive", and "fantasy".
Note: Returned font might have different style if the requested style is not available.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static string GetSystemFontPath(string fontName, int weight = 400, int stretch = 100, bool italic = false)
Parameters
Returns
GetSystemFontPathForText(string, string, string, string, int, int, bool)
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.
The following aliases can be used to request default fonts: "sans-serif", "serif", "monospace", "cursive", and "fantasy".
Note: Depending on OS, it's not guaranteed that any of the returned fonts will be suitable for rendering specified text. Fonts should be loaded and checked in the order they are returned, and the first suitable one used.
Note: Returned fonts might have different style if the requested style is not available or belong to a different font family.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static string[] GetSystemFontPathForText(string fontName, string text, string locale = "", string script = "", int weight = 400, int stretch = 100, bool italic = false)
Parameters
Returns
- string[]
GetSystemFonts()
Returns list of font family names available.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static string[] GetSystemFonts()
Returns
- string[]
GetThreadCallerId()
Returns the ID of the current thread. This can be used in logs to ease debugging of multi-threaded applications.
Note: Thread IDs are not deterministic and may be reused across application restarts.
public static ulong GetThreadCallerId()
Returns
GetUniqueId()
Returns a string that is unique to the device.
Note: This string may change without notice if the user reinstalls/upgrades their operating system or changes their hardware. This means it should generally not be used to encrypt persistent data as the data saved before an unexpected ID change would become inaccessible. The returned string may also be falsified using external programs, so do not rely on the string returned by GetUniqueId() for security purposes.
Note: Returns an empty string and prints an error on Web, as this method cannot be implemented on this platform.
public static string GetUniqueId()
Returns
GetUserDataDir()
Returns the absolute directory path where user data is written (user://
).
On Windows, this is %AppData%\Godot\app_userdata\[project_name]
, or %AppData%\[custom_name]
if use_custom_user_dir
is set. %AppData%
expands to %UserProfile%\AppData\Roaming
.
On macOS, this is ~/Library/Application Support/Godot/app_userdata/[project_name]
, or ~/Library/Application Support/[custom_name]
if use_custom_user_dir
is set.
On Linux and BSD, this is ~/.local/share/godot/app_userdata/[project_name]
, or ~/.local/share/[custom_name]
if use_custom_user_dir
is set.
On Android and iOS, this is a sandboxed directory in either internal or external storage, depending on the user's configuration.
On the web, this is a virtual directory managed by the browser.
If the project name is empty, [project_name]
falls back to [unnamed project]
.
Not to be confused with GetDataDir(), which returns the global (non-project-specific) user home directory.
public static string GetUserDataDir()
Returns
GetVersion()
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.
For Windows, the major and minor version are returned, as well as the build number. For example, the returned string can look like 10.0.9926
for a build of Windows 10, and it can look like 6.1.7601
for a build of Windows 7 SP1.
For rolling distributions, such as Arch Linux, an empty string is returned.
For macOS and iOS, the major and minor version are returned, as well as the patch number.
For Android, the SDK version and the incremental build number are returned. If it's a custom ROM, it attempts to return its version instead.
Note: This method is not supported on the web platform. It returns an empty string.
public static string GetVersion()
Returns
GetVideoAdapterDriverInfo()
Returns the video adapter driver name and version for the user's currently active graphics card. See also GetVideoAdapterApiVersion().
The first element holds the driver name, such as nvidia
, amdgpu
, etc.
The second element holds the driver version. For e.g. the nvidia
driver on a Linux/BSD platform, the version is in the format 510.85.02
. For Windows, the driver's format is 31.0.15.1659
.
Note: This method is only supported on the platforms Linux/BSD and Windows when not running in headless mode. It returns an empty array on other platforms.
public static string[] GetVideoAdapterDriverInfo()
Returns
- string[]
HasEnvironment(string)
Returns true
if the environment variable with the name variable
exists.
Note: Double-check the casing of variable
. Environment variable names are case-sensitive on all platforms except Windows.
public static bool HasEnvironment(string variable)
Parameters
variable
string
Returns
HasFeature(string)
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.
Note: Tag names are case-sensitive.
Note: On the web platform, one of the following additional tags is defined to indicate host platform: web_android
, web_ios
, web_linuxbsd
, web_macos
, or web_windows
.
Note: On the iOS simulator, the additional simulator
tag is defined.
public static bool HasFeature(string tagName)
Parameters
tagName
string
Returns
IsDebugBuild()
Returns true
if the Godot binary used to run the project is a debug export template, or when running in the editor.
Returns false
if the Godot binary used to run the project is a release export template.
To check whether the Godot binary used to run the project is an export template (debug or release), use OS.has_feature("template")
instead.
public static bool IsDebugBuild()
Returns
IsKeycodeUnicode(long)
Returns true
if the input keycode corresponds to a Unicode character.
public static bool IsKeycodeUnicode(long code)
Parameters
code
long
Returns
IsProcessRunning(int)
Returns true
if the child process ID (pid
) is still running or false
if it has terminated.
Must be a valid ID generated from CreateProcess(string, string[], bool).
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static bool IsProcessRunning(int pid)
Parameters
pid
int
Returns
IsRestartOnExitSet()
Returns true
if the project will automatically restart when it exits for any reason, false
otherwise. See also SetRestartOnExit(bool, string[]) and GetRestartOnExitArguments().
public static bool IsRestartOnExitSet()
Returns
IsSandboxed()
Returns true
if application is running in the sandbox.
Note: This method is implemented on macOS and Linux.
public static bool IsSandboxed()
Returns
IsStdOutVerbose()
Returns true
if the engine was executed with the --verbose
or -v
command line argument, or if ProjectSettings.debug/settings/stdout/verbose_stdout
is true
. See also @GlobalScope.print_verbose
.
public static bool IsStdOutVerbose()
Returns
IsUserfsPersistent()
If true
, the user://
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.
public static bool IsUserfsPersistent()
Returns
Kill(int)
Kill (terminate) the process identified by the given process ID (pid
), e.g. the one returned by Execute(string, string[], Array, bool, bool) in non-blocking mode. See also Crash(string).
Note: This method can also be used to kill processes that were not spawned by the game.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
public static Error Kill(int pid)
Parameters
pid
int
Returns
MoveToTrash(string)
Moves the file or directory to the system's recycle bin. See also Remove(string).
The method takes only global paths, so you may need to use GlobalizePath(string). Do not use it for files in res://
as it will not work in exported projects.
Note: If the user has disabled the recycle bin on their system, the file will be permanently deleted instead.
var fileToRemove = "user://slot1.save";
OS.MoveToTrash(ProjectSettings.GlobalizePath(fileToRemove));
public static Error MoveToTrash(string path)
Parameters
path
string
Returns
OpenMidiInputs()
Initializes the singleton for the system MIDI driver.
Note: This method is implemented on Linux, macOS and Windows.
public static void OpenMidiInputs()
ReadStringFromStdIn()
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 calling ReadStringFromStdIn() will block until the program receives a line break in standard input (usually by the user pressing Enter).
Note: This method is implemented on Linux, macOS and Windows.
public static string ReadStringFromStdIn()
Returns
RequestPermission(string)
At the moment this function is only used by AudioDriverOpenSL
to request permission for RECORD_AUDIO
on Android.
public static bool RequestPermission(string name)
Parameters
name
string
Returns
RequestPermissions()
With this function, you can request dangerous permissions since normal permissions are automatically granted at install time in Android applications.
Note: This method is implemented only on Android.
public static bool RequestPermissions()
Returns
RevokeGrantedPermissions()
On macOS (sandboxed applications only), this function clears list of user selected folders accessible to the application.
public static void RevokeGrantedPermissions()
SetEnvironment(string, string)
Sets the value of the environment variable variable
to value
. The environment variable will be set for the Godot process and any process executed with Execute(string, string[], Array, bool, bool) after running SetEnvironment(string, string). The environment variable will not persist to processes run after the Godot process was terminated.
Note: Environment variable names are case-sensitive on all platforms except Windows. The variable
name cannot be empty or include the =
character. On Windows, there is a 32767 characters limit for the combined length of variable
, value
, and the =
and null terminator characters that will be registered in the environment block.
public static void SetEnvironment(string variable, string value)
Parameters
SetRestartOnExit(bool, string[])
If restart
is true
, restarts the project automatically when it is exited with Quit(int) or NotificationWMCloseRequest. Command line arguments
can be supplied. To restart the project with the same command line arguments as originally used to run the project, pass GetCmdlineArgs() as the value for arguments
.
SetRestartOnExit(bool, string[]) can be used to apply setting changes that require a restart. See also IsRestartOnExitSet() and GetRestartOnExitArguments().
Note: This method is only effective on desktop platforms, and only when the project isn't started from the editor. It will have no effect on mobile and Web platforms, or when the project is started from the editor.
Note: If the project process crashes or is killed by the user (by sending SIGKILL
instead of the usual SIGTERM
), the project won't restart automatically.
public static void SetRestartOnExit(bool restart, string[] arguments = null)
Parameters
restart
boolarguments
string[]If the parameter is null, then the default value is
Array.Empty<string>()
.
SetThreadName(string)
Sets the name of the current thread.
public static Error SetThreadName(string name)
Parameters
name
string
Returns
SetUseFileAccessSaveAndSwap(bool)
Enables backup saves if enabled
is true
.
public static void SetUseFileAccessSaveAndSwap(bool enabled)
Parameters
enabled
bool
ShellOpen(string)
Requests the OS to open a resource with the most appropriate program. For example:
- OS.shell_open("C:\\Users\name\Downloads")
on Windows opens the file explorer at the user's Downloads folder.
- OS.shell_open("https://godotengine.org")
opens the default web browser on the official Godot website.
- OS.shell_open("mailto:example@example.com")
opens the default email client with the "To" field set to example@example.com
. See RFC 2368 - The mailto
URL scheme for a list of fields that can be added.
Use GlobalizePath(string) to convert a res://
or user://
path into a system path for use with this method.
Note: Use String.uri_encode
to encode characters within URLs in a URL-safe, portable way. This is especially required for line breaks. Otherwise, ShellOpen(string) may not work correctly in a project exported to the Web platform.
Note: This method is implemented on Android, iOS, Web, Linux, macOS and Windows.
public static Error ShellOpen(string uri)
Parameters
uri
string
Returns
ShellShowInFileManager(string, bool)
Requests the OS to open the file manager, then navigate to the given fileOrDirPath
and select the target file or folder.
If fileOrDirPath
is a valid directory path, and openFolder
is true
, the method will open the file manager and enter the target folder without selecting anything.
Use GlobalizePath(string) to convert a res://
or user://
path into a system path for use with this method.
Note: Currently this method is only implemented on Windows and macOS. On other platforms, it will fallback to ShellOpen(string) with a directory path of fileOrDirPath
with prefix file://
.
public static Error ShellShowInFileManager(string fileOrDirPath, bool openFolder = true)
Parameters
Returns
UnsetEnvironment(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 with Execute(string, string[], Array, bool, bool) after running UnsetEnvironment(string). The removal of the environment variable will not persist to processes run after the Godot process was terminated.
Note: Environment variable names are case-sensitive on all platforms except Windows. The variable
name cannot be empty or include the =
character.
public static void UnsetEnvironment(string variable)
Parameters
variable
string