Operating System functions.
    public static class OS

Operating System functions. OS Wraps the most common functionality to communicate with the host Operating System, such as: mouse grabbing, mouse cursors, clipboard, video mode, date and time, timers, environment variables, execution of binaries, command line, etc.

Inheritance Chain

Static Properties

    public static string Clipboard { get; set; }

The clipboard from the host OS. Might be unavailable on some platforms.

    public static int CurrentScreen { get; set; }

The current screen index (starting from 0).

    public static int ExitCode { get; set; }

The exit code passed to the OS when the main loop exits.

    public static bool KeepScreenOn { get; set; }

If true, the engine tries to keep the screen on while the game is running. Useful on mobile.

    public static bool LowProcessorUsageMode { get; set; }

If true, the engine optimizes for low processor usage by only refreshing the screen if needed. Can improve battery consumption on mobile.

    public static ScreenOrientationEnum ScreenOrientation { get; set; }

The current screen orientation.

    public static Object Singleton { get; }

    public static bool VsyncEnabled { get; set; }

If true, vertical synchronization (Vsync) is enabled.

    public static bool WindowBorderless { get; set; }

If true, removes the window frame.

    public static bool WindowFullscreen { get; set; }

If true, the window is fullscreen.

    public static bool WindowMaximized { get; set; }

If true, the window is maximized.

    public static bool WindowMinimized { get; set; }

If true, the window is minimized.

    public static bool WindowPerPixelTransparencyEnabled { get; set; }

    public static Vector2 WindowPosition { get; set; }

The window position relative to the screen, the origin is the top left corner, +Y axis goes to the bottom and +X axis goes to the right.

    public static bool WindowResizable { get; set; }

If true, the window is resizable by the user.

    public static Vector2 WindowSize { get; set; }

The size of the window (without counting window manager decorations).

Static Methods

    public static void Alert(string text, string title = "Alert!")

Displays a modal dialog box utilizing the host OS.

    public static bool CanDraw()

Returns true if the host OS allows drawing.

    public static bool CanUseThreads()

Returns true if the current host platform is using multiple threads.

    public static void CenterWindow()

Centers the window on the screen if in windowed mode.

    public static void CloseMidiInputs()

    public static void DelayMsec(int msec)

Delay execution of the current thread by given milliseconds.

    public static void DelayUsec(int usec)

Delay execution of the current thread by given microseconds.

    public static void DumpMemoryToFile(string file)

Dumps the memory allocation ringlist to a file (only works in debug).

Entry format per line: “Address - Size - Description”.

    public static void DumpResourcesToFile(string file)

Dumps all used resources to file (only works in debug).

Entry format per line: “Resource Type : Resource Location”.

At the end of the file is a statistic of all used Resource Types.

    public static int Execute(string path, string[] arguments, bool blocking, Godot.Collections.Array output = null)

Execute the file at the given path with the arguments passed as an array of strings. Platform path resolution will take place. The resolved file must exist and be executable.

The arguments are used in the given order and separated by a space, so OS.execute('ping', ["-w", "3", "godotengine.org"], false) will resolve to ping -w 3 godotengine.org in the system’s shell.

This method has slightly different behaviour based on whether the blocking mode is enabled.

When blocking is enabled, the Godot thread will pause its execution while waiting for the process to terminate. The shell output of the process will be written to the output array as a single string. When the process terminates, the Godot thread will resume execution.

When blocking is disabled, the Godot thread will continue while the new process runs. It is not possible to retrieve the shell output in non-blocking mode, so output will be empty.

The return value also depends on the blocking mode. When blocking, the method will return -2 (no process ID information is available in blocking mode). When non-blocking, the method returns a process ID, which you can use to monitor the process (and potentially terminate it with Kill(int)). If the process forking (non-blocking) or opening (blocking) fails, the method will return -1.

Example of blocking mode and retrieving the shell output:

[codeblock]

var output = []

OS.execute(‘ls’, [“-l”, “/tmp”], true, output)

[/codeblock]

Example of non-blocking mode, running another instance of the project and storing its process ID:

[codeblock]

var pid = OS.execute(OS.get_executable_path(), [], false)

[/codeblock]

If you wish to access a shell built-in or perform a composite command, a platform-specific shell can be invoked. For example:

[codeblock]

OS.execute(‘CMD.exe’, [‘/C’, ‘cd %TEMP% && dir’], true, output)

[/codeblock]

    public static int FindScancodeFromString(string @string)

Returns the scancode of the given string (e.g. “Escape”)

    public static int GetAudioDriverCount()

Returns the total number of available audio drivers.

    public static string GetAudioDriverName(int driver)

Returns the audio driver name for the given index.

    public static bool GetBorderlessWindow()

Getter for WindowBorderless

    public static string GetClipboard()

Getter for Clipboard

    public static string[] GetCmdlineArgs()

Returns the command line arguments passed to the engine.

    public static string[] GetConnectedMidiInputs()

    public static int GetCurrentScreen()

Getter for CurrentScreen

    public static VideoDriver GetCurrentVideoDriver()

Returns the currently used video driver, using one of the values from VideoDriver.

    public static Dictionary GetDate(bool utc = false)

Returns current date as a dictionary of keys: year, month, day, weekday, dst (daylight savings time).

    public static Dictionary GetDatetime(bool utc = false)

Returns current datetime as a dictionary of keys: year, month, day, weekday, dst (daylight savings time), hour, minute, second.

    public static Dictionary GetDatetimeFromUnixTime(int unixTimeVal)

Get a dictionary of time values when given epoch time.

Dictionary Time values will be a union of values from GetTime(bool) and GetDate(bool) dictionaries (with the exception of dst = day light standard time, as it cannot be determined from epoch).

    public static int GetDynamicMemoryUsage()

Returns the total amount of dynamic memory used (only works in debug).

    public static string GetEnvironment(string environment)

Returns an environment variable.

    public static string GetExecutablePath()

Returns the path to the current engine executable.

    public static int GetExitCode()

Getter for ExitCode

    public static Vector2 GetImeSelection()

Returns IME selection range.

    public static string GetImeText()

Returns IME intermediate text.

    public static string GetLatinKeyboardVariant()

Returns the current latin keyboard variant as a String.

Possible return values are: “QWERTY”, “AZERTY”, “QZERTY”, “DVORAK”, “NEO”, “COLEMAK” or “ERROR”.

    public static string GetLocale()

Returns the host OS locale.

    public static string GetModelName()

Returns the model name of the current device.

    public static string GetName()

Returns the name of the host OS. Possible values are: “Android”, “Haiku”, “iOS”, “HTML5”, “OSX”, “Server”, “Windows”, “UWP”, “X11”.

    public static int GetPowerPercentLeft()

Returns the amount of battery left in the device as a percentage.

    public static int GetPowerSecondsLeft()

Returns the time in seconds before the device runs out of battery.

    public static PowerState GetPowerState()

Returns the current state of the device regarding battery and power. See POWERSTATE_* constants.

    public static int GetProcessId()

Returns the game process ID

    public static int GetProcessorCount()

Returns the number of cores available in the host machine.

    public static Vector2 GetRealWindowSize()

Returns the window size including decorations like window borders.

    public static string GetScancodeString(int code)

Returns the given scancode as a string (e.g. Return values: “Escape”, “Shift+Escape”).

    public static int GetScreenCount()

Returns the number of displays attached to the host machine.

    public static int GetScreenDpi(int screen = -1)

Returns the dots per inch density of the specified screen.

On Android Devices, the actual screen densities are grouped into six generalized densities:

ldpi - 120 dpi

mdpi - 160 dpi

hdpi - 240 dpi

xhdpi - 320 dpi

xxhdpi - 480 dpi

xxxhdpi - 640 dpi

    public static ScreenOrientationEnum GetScreenOrientation()

Getter for ScreenOrientation

    public static Vector2 GetScreenPosition(int screen = -1)

Returns the position of the specified screen by index. If no screen index is provided, the current screen will be used.

    public static Vector2 GetScreenSize(int screen = -1)

Returns the dimensions in pixels of the specified screen.

    public static int GetSplashTickMsec()

    public static int GetStaticMemoryPeakUsage()

Returns the max amount of static memory used (only works in debug).

    public static int GetStaticMemoryUsage()

Returns the amount of static memory being used by the program in bytes.

    public static string GetSystemDir(SystemDir dir)

Returns the actual path to commonly used folders across different platforms. Available locations are specified in SystemDir.

    public static int GetSystemTimeMsecs()

Returns the epoch time of the operating system in milliseconds.

    public static int GetSystemTimeSecs()

Returns the epoch time of the operating system in seconds.

    public static int GetTicksMsec()

Returns the amount of time passed in milliseconds since the engine started.

    public static int GetTicksUsec()

Returns the amount of time passed in microseconds since the engine started.

    public static Dictionary GetTime(bool utc = false)

Returns current time as a dictionary of keys: hour, minute, second.

    public static Dictionary GetTimeZoneInfo()

Returns the current time zone as a dictionary with the keys: bias and name.

    public static string GetUniqueId()

Returns a string that is unique to the device.

Returns empty string on HTML5 and UWP which are not supported yet.

    public static int GetUnixTime()

Returns the current unix epoch timestamp.

    public static int GetUnixTimeFromDatetime(Dictionary datetime)

Get an epoch time value from a dictionary of time values.

datetime must be populated with the following keys: year, month, day, hour, minute, second.

You can pass the output from GetDatetimeFromUnixTime(int) directly into this function. Daylight savings time (dst), if present, is ignored.

    public static string GetUserDataDir()

Returns the absolute directory path where user data is written (user://).

On Linux, this is ~/.local/share/godot/app_userdata/[project_name], or ~/.local/share/[custom_name] if use_custom_user_dir is set.

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 Windows, this is %APPDATA%/Godot/app_userdata/[project_name], or %APPDATA%/[custom_name] if use_custom_user_dir is set.

If the project name is empty, user:// falls back to res://.

    public static int GetVideoDriverCount()

Returns the number of video drivers supported on the current platform.

    public static string GetVideoDriverName(VideoDriver driver)

Returns the name of the video driver matching the given driver index. This index is a value from VideoDriver, and you can use GetCurrentVideoDriver() to get the current backend’s index.

    public static int GetVirtualKeyboardHeight()

Returns the on-screen keyboard’s height in pixels. Returns 0 if there is no keyboard or it is currently hidden.

    public static bool GetWindowPerPixelTransparencyEnabled()

Getter for WindowPerPixelTransparencyEnabled

    public static Vector2 GetWindowPosition()

Getter for WindowPosition

    public static Rect2 GetWindowSafeArea()

    public static Vector2 GetWindowSize()

Getter for WindowSize

    public static bool HasEnvironment(string environment)

Returns true if an environment variable exists.

    public static bool HasFeature(string tagName)

Returns true if the feature for the given feature tag is supported in the currently running instance, depending on platform, build etc. Can be used to check whether you’re currently running a debug build, on a certain platform or arch, etc. See feature tags documentation.

    public static bool HasTouchscreenUiHint()

Returns true if the device has a touchscreen or emulates one.

    public static bool HasVirtualKeyboard()

Returns true if the platform has a virtual keyboard, false otherwise.

    public static void HideVirtualKeyboard()

Hides the virtual keyboard if it is shown, does nothing otherwise.

    public static bool IsDebugBuild()

Returns true if the build is a debug build.

Returns true when running in the editor.

Returns false if the build is a release build.

    public static bool IsInLowProcessorUsageMode()

Getter for LowProcessorUsageMode

    public static bool IsKeepScreenOn()

Getter for KeepScreenOn

    public static bool IsOkLeftAndCancelRight()

Returns true if the “Okay” button should appear on the left and “Cancel” on the right.

    public static bool IsScancodeUnicode(int code)

Returns true if the input code has a unicode character.

    public static bool IsStdoutVerbose()

Returns true if the engine was executed with -v (verbose stdout).

    public static bool 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 HTML5 platform, where this persistence may be unavailable.

    public static bool IsVsyncEnabled()

Getter for VsyncEnabled

    public static bool IsWindowAlwaysOnTop()

Returns true if the window should always be on top of other windows.

    public static bool IsWindowFullscreen()

Getter for WindowFullscreen

    public static bool IsWindowMaximized()

Getter for WindowMaximized

    public static bool IsWindowMinimized()

Getter for WindowMinimized

    public static bool IsWindowResizable()

Getter for WindowResizable

    public static Error Kill(int pid)

Kill (terminate) the process identified by the given process ID (pid), e.g. the one returned by Execute(string, string[], bool, Godot.Collections.Array) in non-blocking mode.

Note that this method can also be used to kill processes that were not spawned by the game.

    public static void MoveWindowToForeground()

Moves the window to the front.

    public static bool NativeVideoIsPlaying()

Returns true if native video is playing.

    public static void NativeVideoPause()

Pauses native video playback.

    public static Error NativeVideoPlay(string path, float volume, string audioTrack, string subtitleTrack)

Plays native video from the specified path, at the given volume and with audio and subtitle tracks.

Note: This method is only implemented on Android and iOS, and the current Android implementation does not support the volume, audioTrack and subtitleTrack options.

    public static void NativeVideoStop()

Stops native video playback.

    public static void NativeVideoUnpause()

Resumes native video playback.

    public static void OpenMidiInputs()

    public static void PrintAllResources(string tofile = "")

Shows all resources in the game. Optionally the list can be written to a file.

    public static void PrintAllTexturesBySize()

Shows the list of loaded textures sorted by size in memory.

    public static void PrintResourcesByType(string[] types)

Shows the number of resources loaded by the game of the given types.

    public static void PrintResourcesInUse(bool @short = false)

Shows all resources currently used by the game.

    public static void RequestAttention()

Request the user attention to the window. It’ll flash the taskbar button on Windows or bounce the dock icon on OSX.

    public static void SetBorderlessWindow(bool borderless)

Setter for WindowBorderless

    public static void SetClipboard(string clipboard)

Setter for Clipboard

    public static void SetCurrentScreen(int screen)

Setter for CurrentScreen

    public static void SetExitCode(int code)

Setter for ExitCode

    public static void SetIcon(Image icon)

Sets the game’s icon.

    public static void SetImeActive(bool active)

Sets whether IME input mode should be enabled.

    public static void SetImePosition(Vector2 position)

Sets position of IME suggestion list popup (in window coordinates).

    public static void SetKeepScreenOn(bool enabled)

Setter for KeepScreenOn

    public static void SetLowProcessorUsageMode(bool enable)

Setter for LowProcessorUsageMode

    public static void SetScreenOrientation(ScreenOrientationEnum orientation)

Setter for ScreenOrientation

    public static Error SetThreadName(string name)

Sets the name of the current thread.

    public static void SetUseFileAccessSaveAndSwap(bool enabled)

Enables backup saves if enabled is true.

    public static void SetUseVsync(bool enable)

Setter for VsyncEnabled

    public static void SetWindowAlwaysOnTop(bool enabled)

Sets whether the window should always be on top.

    public static void SetWindowFullscreen(bool enabled)

Setter for WindowFullscreen

    public static void SetWindowMaximized(bool enabled)

Setter for WindowMaximized

    public static void SetWindowMinimized(bool enabled)

Setter for WindowMinimized

    public static void SetWindowPerPixelTransparencyEnabled(bool enabled)

Setter for WindowPerPixelTransparencyEnabled

    public static void SetWindowPosition(Vector2 position)

Setter for WindowPosition

    public static void SetWindowResizable(bool enabled)

Setter for WindowResizable

    public static void SetWindowSize(Vector2 size)

Setter for WindowSize

    public static void SetWindowTitle(string title)

Sets the window title to the specified string.

    public static Error ShellOpen(string uri)

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 downloads folders of the user.

OS.shell_open("https://godotengine.org") opens the default web browser on the official Godot website.

    public static void ShowVirtualKeyboard(string existingText = "")

Shows the virtual keyboard if the platform has one. The existing_text parameter is useful for implementing your own LineEdit, as it tells the virtual keyboard what text has already been typed (the virtual keyboard uses it for auto-correct and predictions).

Inner Types

Month

Name Value Description
January 1 January.
February 2 February.
March 3 March.
April 4 April.
May 5 May.
June 6 June.
July 7 July.
August 8 August.
September 9 September.
October 10 October.
November 11 November.
December 12 December.

PowerState

Name Value Description
Unknown 0 Unknown powerstate.
OnBattery 1 Unplugged, running on battery.
NoBattery 2 Plugged in, no battery available.
Charging 3 Plugged in, battery charging.
Charged 4 Plugged in, battery fully charged.

ScreenOrientationEnum

Name Value Description
Landscape 0 Landscape screen orientation.
Portrait 1 Portrait screen orientation.
ReverseLandscape 2 Reverse landscape screen orientation.
ReversePortrait 3 Reverse portrait screen orientation.
SensorLandscape 4 Uses landscape or reverse landscape based on the hardware sensor.
SensorPortrait 5 Uses portrait or reverse portrait based on the hardware sensor.
Sensor 6 Uses most suitable orientation based on the hardware sensor.

SystemDir

Name Value Description
Desktop 0 Desktop directory path.
Dcim 1 DCIM (Digital Camera Images) directory path.
Documents 2 Documents directory path.
Downloads 3 Downloads directory path.
Movies 4 Movies directory path.
Music 5 Music directory path.
Pictures 6 Pictures directory path.
Ringtones 7 Ringtones directory path.

VideoDriver

Name Value Description
Gles2    
Gles3    

Weekday

Name Value Description
Sunday 0 Sunday.
Monday 1 Monday.
Tuesday 2 Tuesday.
Wednesday 3 Wednesday.
Thursday 4 Thursday.
Friday 5 Friday.
Saturday 6 Saturday.
Tags: