Struct Os
pub struct Os { /* private fields */ }Expand description
Godot class OS.
Inherits Object.
Related symbols:
os: sidecar module with related enum/flag types
See also Godot docs for OS.
§Singleton
This class is a singleton. You can get the one instance using Singleton::singleton().
§Final class
This class is final, meaning you cannot inherit from it, and it comes without I* interface trait. It is still possible that other Godot classes inherit from it, but that is limited to the engine itself.
§Godot docs
The OS 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, clipboard, and TTS were moved to the DisplayServer singleton (and the Window class). Functions related to time were removed and are only available in the Time class.
Implementations§
§impl Os
impl Os
pub fn get_entropy(&self, size: i32) -> PackedArray<u8>
pub fn get_entropy(&self, size: i32) -> PackedArray<u8>
Generates a PackedByteArray of cryptographically secure random bytes with given size.
Note: Generating large quantities of bytes using this method can result in locking and entropy of lower quality on most platforms. Using generate_random_bytes is preferred in most cases.
pub fn get_system_ca_certificates(&self) -> GString
pub fn get_system_ca_certificates(&self) -> GString
Returns the list of certification authorities trusted by the operating system as a string of concatenated certificates in PEM format.
pub fn get_connected_midi_inputs(&self) -> PackedArray<GString>
pub fn get_connected_midi_inputs(&self) -> PackedArray<GString>
Returns an array of connected MIDI device names, if they exist. Returns an empty array if the system MIDI driver has not previously been initialized with open_midi_inputs. See also close_midi_inputs.
Note: This method is implemented on Linux, macOS, Windows, and Web.
Note: On the Web platform, Web MIDI needs to be supported by the browser. For the time being, it is currently supported by all major browsers, except Safari.
Note: On the Web platform, using MIDI input requires a browser permission to be granted first. This permission request is performed when calling open_midi_inputs. The browser will refrain from processing MIDI input until the user accepts the permission request.
pub fn open_midi_inputs(&mut self)
pub fn open_midi_inputs(&mut self)
Initializes the singleton for the system MIDI driver, allowing Godot to receive InputEventMIDI. See also get_connected_midi_inputs and close_midi_inputs.
Note: This method is implemented on Linux, macOS, Windows, and Web.
Note: On the Web platform, Web MIDI needs to be supported by the browser. For the time being, it is currently supported by all major browsers, except Safari.
Note: On the Web platform, using MIDI input requires a browser permission to be granted first. This permission request is performed when calling open_midi_inputs. The browser will refrain from processing MIDI input until the user accepts the permission request.
pub fn close_midi_inputs(&mut self)
pub fn close_midi_inputs(&mut self)
Shuts down the system MIDI driver. Godot will no longer receive InputEventMIDI. See also open_midi_inputs and get_connected_midi_inputs.
Note: This method is implemented on Linux, macOS, Windows, and Web.
pub fn alert_ex<'ex>(
&'ex mut self,
text: impl AsArg<GString> + 'ex,
) -> ExAlert<'ex>
pub fn alert_ex<'ex>( &'ex mut self, text: impl AsArg<GString> + 'ex, ) -> ExAlert<'ex>
Displays a modal dialog box using the host platform’s implementation. The engine execution is blocked until the dialog is closed.
pub fn crash(&mut self, message: impl AsArg<GString>)
pub fn crash(&mut self, message: impl AsArg<GString>)
Crashes the engine (or the editor if called within a @tool script). See also kill.
Note: This method 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) [method @GDScript.assert], push_error, or alert.
pub fn set_low_processor_usage_mode(&mut self, enable: bool)
pub fn is_in_low_processor_usage_mode(&self) -> bool
pub fn set_low_processor_usage_mode_sleep_usec(&mut self, usec: i32)
pub fn get_low_processor_usage_mode_sleep_usec(&self) -> i32
pub fn set_delta_smoothing(&mut self, delta_smoothing_enabled: bool)
pub fn is_delta_smoothing_enabled(&self) -> bool
pub fn get_processor_count(&self) -> i32
pub fn get_processor_count(&self) -> i32
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.
pub fn get_processor_name(&self) -> GString
pub fn get_processor_name(&self) -> GString
Returns the full 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, get_processor_name returns an empty string.
pub fn get_system_fonts(&self) -> PackedArray<GString>
pub fn get_system_fonts(&self) -> PackedArray<GString>
Returns the list of font family names available.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
pub fn get_system_font_path(&self, font_name: impl AsArg<GString>) -> GString
pub fn get_system_font_path(&self, font_name: impl AsArg<GString>) -> GString
To set the default parameters, use get_system_font_path_ex and its builder methods. See the book for detailed usage instructions.
Returns the path to the system font file with font_name and style. Returns an 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.
pub fn get_system_font_path_ex<'ex>(
&'ex self,
font_name: impl AsArg<GString> + 'ex,
) -> ExGetSystemFontPath<'ex>
pub fn get_system_font_path_ex<'ex>( &'ex self, font_name: impl AsArg<GString> + 'ex, ) -> ExGetSystemFontPath<'ex>
Returns the path to the system font file with font_name and style. Returns an 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.
pub fn get_system_font_path_for_text(
&self,
font_name: impl AsArg<GString>,
text: impl AsArg<GString>,
) -> PackedArray<GString>
pub fn get_system_font_path_for_text( &self, font_name: impl AsArg<GString>, text: impl AsArg<GString>, ) -> PackedArray<GString>
To set the default parameters, use get_system_font_path_for_text_ex and its builder methods. See the book for detailed usage instructions.
Returns an array of the system substitute font file paths, which are similar to the font with font_name and style for the specified text, locale, and script. Returns an 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.
pub fn get_system_font_path_for_text_ex<'ex>(
&'ex self,
font_name: impl AsArg<GString> + 'ex,
text: impl AsArg<GString> + 'ex,
) -> ExGetSystemFontPathForText<'ex>
pub fn get_system_font_path_for_text_ex<'ex>( &'ex self, font_name: impl AsArg<GString> + 'ex, text: impl AsArg<GString> + 'ex, ) -> ExGetSystemFontPathForText<'ex>
Returns an array of the system substitute font file paths, which are similar to the font with font_name and style for the specified text, locale, and script. Returns an 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.
pub fn get_executable_path(&self) -> GString
pub fn get_executable_path(&self) -> GString
Returns the file path to the current engine executable.
Note: On macOS, if you want to launch another instance of Godot, always use create_instance instead of relying on the executable path.
pub fn read_string_from_stdin(&mut self) -> GString
pub fn read_string_from_stdin(&mut self) -> GString
To set the default parameters, use read_string_from_stdin_ex and its builder methods. See the book for detailed usage instructions.
Reads a user input as a UTF-8 encoded string from the standard input. This operation can be blocking, which causes the window to freeze if read_string_from_stdin is called on the main thread.
-
If standard input is console, this method will block until the program receives a line break in standard input (usually by the user pressing
Enter). -
If standard input is pipe, this method will block until a specific amount of data is read or pipe is closed.
-
If standard input is a file, this method will read a specific amount of data (or less if end-of-file is reached) and return immediately.
Note: This method automatically replaces \r\n line breaks with \n and removes them from the end of the string. Use read_buffer_from_stdin to read the unprocessed data.
Note: This method is implemented on Linux, macOS, and Windows.
Note: On exported Windows builds, run the console wrapper executable to access the terminal. If standard input is console, calling this method without console wrapped will freeze permanently. If standard input is pipe or file, it can be used without console wrapper. If you need a single executable with full console support, use a custom build compiled with the windows_subsystem=console flag.
pub fn read_string_from_stdin_ex<'ex>(
&'ex mut self,
) -> ExReadStringFromStdin<'ex>
pub fn read_string_from_stdin_ex<'ex>( &'ex mut self, ) -> ExReadStringFromStdin<'ex>
Reads a user input as a UTF-8 encoded string from the standard input. This operation can be blocking, which causes the window to freeze if read_string_from_stdin is called on the main thread.
-
If standard input is console, this method will block until the program receives a line break in standard input (usually by the user pressing
Enter). -
If standard input is pipe, this method will block until a specific amount of data is read or pipe is closed.
-
If standard input is a file, this method will read a specific amount of data (or less if end-of-file is reached) and return immediately.
Note: This method automatically replaces \r\n line breaks with \n and removes them from the end of the string. Use read_buffer_from_stdin to read the unprocessed data.
Note: This method is implemented on Linux, macOS, and Windows.
Note: On exported Windows builds, run the console wrapper executable to access the terminal. If standard input is console, calling this method without console wrapped will freeze permanently. If standard input is pipe or file, it can be used without console wrapper. If you need a single executable with full console support, use a custom build compiled with the windows_subsystem=console flag.
pub fn read_buffer_from_stdin(&mut self) -> PackedArray<u8>
pub fn read_buffer_from_stdin(&mut self) -> PackedArray<u8>
To set the default parameters, use read_buffer_from_stdin_ex and its builder methods. See the book for detailed usage instructions.
Reads a user input as raw data from the standard input. This operation can be blocking, which causes the window to freeze if read_buffer_from_stdin is called on the main thread.
-
If standard input is console, this method will block until the program receives a line break in standard input (usually by the user pressing
Enter). -
If standard input is pipe, this method will block until a specific amount of data is read or pipe is closed.
-
If standard input is a file, this method will read a specific amount of data (or less if end-of-file is reached) and return immediately.
Note: This method is implemented on Linux, macOS, and Windows.
Note: On exported Windows builds, run the console wrapper executable to access the terminal. If standard input is console, calling this method without console wrapped will freeze permanently. If standard input is pipe or file, it can be used without console wrapper. If you need a single executable with full console support, use a custom build compiled with the windows_subsystem=console flag.
pub fn read_buffer_from_stdin_ex<'ex>(
&'ex mut self,
) -> ExReadBufferFromStdin<'ex>
pub fn read_buffer_from_stdin_ex<'ex>( &'ex mut self, ) -> ExReadBufferFromStdin<'ex>
Reads a user input as raw data from the standard input. This operation can be blocking, which causes the window to freeze if read_buffer_from_stdin is called on the main thread.
-
If standard input is console, this method will block until the program receives a line break in standard input (usually by the user pressing
Enter). -
If standard input is pipe, this method will block until a specific amount of data is read or pipe is closed.
-
If standard input is a file, this method will read a specific amount of data (or less if end-of-file is reached) and return immediately.
Note: This method is implemented on Linux, macOS, and Windows.
Note: On exported Windows builds, run the console wrapper executable to access the terminal. If standard input is console, calling this method without console wrapped will freeze permanently. If standard input is pipe or file, it can be used without console wrapper. If you need a single executable with full console support, use a custom build compiled with the windows_subsystem=console flag.
pub fn get_stdin_type(&self) -> StdHandleType
pub fn get_stdin_type(&self) -> StdHandleType
Returns the type of the standard input device.
Note: This method is implemented on Linux, macOS, and Windows.
Note: On exported Windows builds, run the console wrapper executable to access the standard input. If you need a single executable with full console support, use a custom build compiled with the windows_subsystem=console flag.
pub fn get_stdout_type(&self) -> StdHandleType
pub fn get_stdout_type(&self) -> StdHandleType
Returns the type of the standard output device.
Note: This method is implemented on Linux, macOS, and Windows.
pub fn get_stderr_type(&self) -> StdHandleType
pub fn get_stderr_type(&self) -> StdHandleType
Returns the type of the standard error device.
Note: This method is implemented on Linux, macOS, and Windows.
pub fn execute(
&mut self,
path: impl AsArg<GString>,
arguments: &PackedArray<GString>,
) -> i32
pub fn execute( &mut self, path: impl AsArg<GString>, arguments: &PackedArray<GString>, ) -> i32
To set the default parameters, use execute_ex and its builder methods. See the book for detailed usage instructions.
Executes the given process in a blocking way. The file specified in path must exist and be executable. The system 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 is appended to output as a single String element. If read_stderr is true, the output to the standard error stream is also appended to the array.
On Windows, if open_console is true and the process is a console app, a new terminal window is opened.
This method returns the exit code of the command, or -1 if the process fails to execute.
Note: The main thread will be blocked until the executed command terminates. Use Thread to create a separate thread that will not block the main thread, or use create_process to create a completely independent process.
For example, to retrieve a list of the working directory’s contents:
var output = []
var exit_code = OS.execute("ls", ["-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 = []
OS.execute("CMD.exe", ["/C", "cd %TEMP% && dir"], output)Note: This method is implemented on Android, 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.
pub fn execute_ex<'ex>(
&'ex mut self,
path: impl AsArg<GString> + 'ex,
arguments: &'ex PackedArray<GString>,
) -> ExExecute<'ex>
pub fn execute_ex<'ex>( &'ex mut self, path: impl AsArg<GString> + 'ex, arguments: &'ex PackedArray<GString>, ) -> ExExecute<'ex>
Executes the given process in a blocking way. The file specified in path must exist and be executable. The system 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 is appended to output as a single String element. If read_stderr is true, the output to the standard error stream is also appended to the array.
On Windows, if open_console is true and the process is a console app, a new terminal window is opened.
This method returns the exit code of the command, or -1 if the process fails to execute.
Note: The main thread will be blocked until the executed command terminates. Use Thread to create a separate thread that will not block the main thread, or use create_process to create a completely independent process.
For example, to retrieve a list of the working directory’s contents:
var output = []
var exit_code = OS.execute("ls", ["-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 = []
OS.execute("CMD.exe", ["/C", "cd %TEMP% && dir"], output)Note: This method is implemented on Android, 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.
pub fn execute_with_pipe(
&mut self,
path: impl AsArg<GString>,
arguments: &PackedArray<GString>,
) -> Dictionary<Variant, Variant>
pub fn execute_with_pipe( &mut self, path: impl AsArg<GString>, arguments: &PackedArray<GString>, ) -> Dictionary<Variant, Variant>
To set the default parameters, use execute_with_pipe_ex and its builder methods. See the book for detailed usage instructions.
Creates a new process that runs independently of Godot with redirected IO. It will not terminate when Godot terminates. The path specified in path must exist and be an executable file or macOS .app bundle. The path is resolved based on the current platform. The arguments are used in the given order and separated by a space.
If blocking is false, created pipes work in non-blocking mode, i.e. read and write operations will return immediately. Use get_error to check if the last read/write operation was successful.
If the process cannot be created, this method returns an empty Dictionary. Otherwise, this method returns a Dictionary with the following keys:
-
"stdio"-FileAccessto access the process stdin and stdout pipes (read/write). -
"stderr"-FileAccessto access the process stderr pipe (read only). -
"pid"- Process ID as anint, which you can use to monitor the process (and potentially terminate it withkill).
Note: This method is implemented on Android, 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 or system .app bundle, system .app bundles will ignore arguments.
pub fn execute_with_pipe_ex<'ex>(
&'ex mut self,
path: impl AsArg<GString> + 'ex,
arguments: &'ex PackedArray<GString>,
) -> ExExecuteWithPipe<'ex>
pub fn execute_with_pipe_ex<'ex>( &'ex mut self, path: impl AsArg<GString> + 'ex, arguments: &'ex PackedArray<GString>, ) -> ExExecuteWithPipe<'ex>
Creates a new process that runs independently of Godot with redirected IO. It will not terminate when Godot terminates. The path specified in path must exist and be an executable file or macOS .app bundle. The path is resolved based on the current platform. The arguments are used in the given order and separated by a space.
If blocking is false, created pipes work in non-blocking mode, i.e. read and write operations will return immediately. Use get_error to check if the last read/write operation was successful.
If the process cannot be created, this method returns an empty Dictionary. Otherwise, this method returns a Dictionary with the following keys:
-
"stdio"-FileAccessto access the process stdin and stdout pipes (read/write). -
"stderr"-FileAccessto access the process stderr pipe (read only). -
"pid"- Process ID as anint, which you can use to monitor the process (and potentially terminate it withkill).
Note: This method is implemented on Android, 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 or system .app bundle, system .app bundles will ignore arguments.
pub fn create_process(
&mut self,
path: impl AsArg<GString>,
arguments: &PackedArray<GString>,
) -> i32
pub fn create_process( &mut self, path: impl AsArg<GString>, arguments: &PackedArray<GString>, ) -> i32
To set the default parameters, use create_process_ex and its builder methods. See the book for detailed usage instructions.
Creates a new process that runs independently of Godot. It will not terminate when Godot terminates. The path specified in path must exist and be an executable file or macOS .app bundle. The path is resolved based on the current platform. The arguments are used in the given order and separated by a space.
On Windows, if open_console is true and the process is a console app, a new terminal window will be opened.
If the process is successfully created, this method returns its process ID, which you can use to monitor the process (and potentially terminate it with kill). Otherwise, this method returns -1.
Example: Run another instance of the project:
var pid = OS.create_process(OS.get_executable_path(), [])See execute if you wish to run an external command and retrieve the results.
Note: This method is implemented on Android, 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.
pub fn create_process_ex<'ex>(
&'ex mut self,
path: impl AsArg<GString> + 'ex,
arguments: &'ex PackedArray<GString>,
) -> ExCreateProcess<'ex>
pub fn create_process_ex<'ex>( &'ex mut self, path: impl AsArg<GString> + 'ex, arguments: &'ex PackedArray<GString>, ) -> ExCreateProcess<'ex>
Creates a new process that runs independently of Godot. It will not terminate when Godot terminates. The path specified in path must exist and be an executable file or macOS .app bundle. The path is resolved based on the current platform. The arguments are used in the given order and separated by a space.
On Windows, if open_console is true and the process is a console app, a new terminal window will be opened.
If the process is successfully created, this method returns its process ID, which you can use to monitor the process (and potentially terminate it with kill). Otherwise, this method returns -1.
Example: Run another instance of the project:
var pid = OS.create_process(OS.get_executable_path(), [])See execute if you wish to run an external command and retrieve the results.
Note: This method is implemented on Android, 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.
pub fn create_instance(&mut self, arguments: &PackedArray<GString>) -> i32
pub fn create_instance(&mut self, arguments: &PackedArray<GString>) -> i32
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 is successfully created, this method returns the new process’ ID, which you can use to monitor the process (and potentially terminate it with kill). If the process cannot be created, this method returns -1.
See create_process if you wish to run a different process.
Note: This method is implemented on Android, Linux, macOS and Windows.
pub fn open_with_program(
&mut self,
program_path: impl AsArg<GString>,
paths: &PackedArray<GString>,
) -> Error
pub fn open_with_program( &mut self, program_path: impl AsArg<GString>, paths: &PackedArray<GString>, ) -> Error
Opens one or more files/directories with the specified application. The program_path specifies the path to the application to use for opening the files, and paths contains an array of file/directory paths to open.
Note: This method is mostly only relevant for macOS, where opening files using create_process might fail. On other platforms, this falls back to using create_process.
Note: On macOS, program_path should ideally be the path to a .app bundle.
pub fn kill(&mut self, pid: i32) -> Error
pub fn kill(&mut self, pid: i32) -> Error
Kill (terminate) the process identified by the given process ID (pid), such as the ID returned by execute in non-blocking mode. See also crash.
Note: This method can also be used to kill processes that were not spawned by the engine.
Note: This method is implemented on Android, iOS, Linux, macOS and Windows.
pub fn shell_open(&mut self, uri: impl AsArg<GString>) -> Error
pub fn shell_open(&mut self, uri: impl AsArg<GString>) -> Error
Requests the OS to open a resource identified by uri 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("C:/Users/name/Downloads")also works on Windows and 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 toexample@example.com. See RFC 2368 - ThemailtoURL scheme for a list of fields that can be added.
Use globalize_path to convert a res:// or user:// project path into a system path for use with this method.
Note: Use uri_encode to encode characters within URLs in a URL-safe, portable way. This is especially required for line breaks. Otherwise, shell_open 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.
pub fn shell_show_in_file_manager(
&mut self,
file_or_dir_path: impl AsArg<GString>,
) -> Error
pub fn shell_show_in_file_manager( &mut self, file_or_dir_path: impl AsArg<GString>, ) -> Error
To set the default parameters, use shell_show_in_file_manager_ex and its builder methods. See the book for detailed usage instructions.
Requests the OS to open the file manager, navigate to the given file_or_dir_path and select the target file or folder.
If open_folder is true and file_or_dir_path is a valid directory path, the OS will open the file manager and navigate to the target folder without selecting anything.
Use globalize_path to convert a res:// or user:// project path into a system path to use with this method.
Note: This method is currently only implemented on Windows and macOS. On other platforms, it will fallback to shell_open with a directory path of file_or_dir_path prefixed with file://.
pub fn shell_show_in_file_manager_ex<'ex>(
&'ex mut self,
file_or_dir_path: impl AsArg<GString> + 'ex,
) -> ExShellShowInFileManager<'ex>
pub fn shell_show_in_file_manager_ex<'ex>( &'ex mut self, file_or_dir_path: impl AsArg<GString> + 'ex, ) -> ExShellShowInFileManager<'ex>
Requests the OS to open the file manager, navigate to the given file_or_dir_path and select the target file or folder.
If open_folder is true and file_or_dir_path is a valid directory path, the OS will open the file manager and navigate to the target folder without selecting anything.
Use globalize_path to convert a res:// or user:// project path into a system path to use with this method.
Note: This method is currently only implemented on Windows and macOS. On other platforms, it will fallback to shell_open with a directory path of file_or_dir_path prefixed with file://.
pub fn is_process_running(&self, pid: i32) -> bool
pub fn is_process_running(&self, pid: i32) -> bool
Returns true if the child process ID (pid) is still running or false if it has terminated. pid must be a valid ID generated from create_process.
Note: This method is implemented on Android, iOS, Linux, macOS, and Windows.
pub fn get_process_exit_code(&self, pid: i32) -> i32
pub fn get_process_exit_code(&self, pid: i32) -> i32
Returns the exit code of a spawned process once it has finished running (see is_process_running).
Returns -1 if the pid is not a PID of a spawned child process, the process is still running, or the method is not implemented for the current platform.
Note: Returns -1 if the pid is a macOS bundled app process.
Note: This method is implemented on Android, Linux, macOS and Windows.
pub fn get_process_id(&self) -> i32
pub fn get_process_id(&self) -> i32
Returns the number used by the host machine to uniquely identify this application.
Note: On Web, this method always returns 0.
pub fn has_environment(&self, variable: impl AsArg<GString>) -> bool
pub fn has_environment(&self, variable: impl AsArg<GString>) -> bool
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.
pub fn get_environment(&self, variable: impl AsArg<GString>) -> GString
pub fn get_environment(&self, variable: impl AsArg<GString>) -> GString
Returns the value of the given environment variable, or an empty string if variable doesn’t exist.
Note: Double-check the casing of variable. Environment variable names are case-sensitive on all platforms except Windows.
Note: On macOS, applications do not have access to shell environment variables.
pub fn set_environment(
&self,
variable: impl AsArg<GString>,
value: impl AsArg<GString>,
)
pub fn set_environment( &self, variable: impl AsArg<GString>, value: impl AsArg<GString>, )
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 after running set_environment. 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.
pub fn unset_environment(&self, variable: impl AsArg<GString>)
pub fn unset_environment(&self, variable: impl AsArg<GString>)
Removes the given environment variable from the current environment, if it exists. The variable name cannot be empty or include the = character. The environment variable will be removed for the Godot process and any process executed with execute after running unset_environment. 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.
pub fn get_name(&self) -> GString
pub fn get_name(&self) -> GString
Returns the name of the host platform.
-
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 Web, this is
"Web".
Note: Custom builds of the engine may support additional platforms, such as consoles, possibly returning other names.
match OS.get_name():
"Windows":
print("Welcome to Windows!")
"macOS":
print("Welcome to macOS!")
"Linux", "FreeBSD", "NetBSD", "OpenBSD", "BSD":
print("Welcome to Linux/BSD!")
"Android":
print("Welcome to Android!")
"iOS":
print("Welcome to iOS!")
"Web":
print("Welcome to the Web!")Note: On Web platforms, it is still possible to determine the host platform’s OS with feature tags. See has_feature.
pub fn get_distribution_name(&self) -> GString
pub fn get_distribution_name(&self) -> GString
Returns the name of the distribution for Linux and BSD platforms (e.g. “Ubuntu”, “Manjaro”, “OpenBSD”, etc.).
Returns the same value as get_name for stock Android ROMs, but attempts to return the custom ROM name for popular Android derivatives such as “LineageOS”.
Returns the same value as get_name for other platforms.
Note: This method is not supported on the Web platform. It returns an empty string.
pub fn get_version(&self) -> GString
pub fn get_version(&self) -> GString
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 may look like
10.0.9926for a build of Windows 10. -
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.
pub fn get_version_alias(&self) -> GString
pub fn get_version_alias(&self) -> GString
Returns the branded version used in marketing, followed by the build number (on Windows), the version number (on macOS), or the SDK version and incremental build number (on Android). Examples include 11 (build 22000), Sequoia (15.0.0), and 15 (SDK 35 build abc528-11988f).
This value can then be appended to get_name to get a full, human-readable operating system name and version combination for the operating system. Windows feature updates such as 24H2 are not contained in the resulting string, but Windows Server is recognized as such (e.g. 2025 (build 26100) for Windows Server 2025).
Note: This method is only supported on Windows, macOS, and Android. On other operating systems, it returns the same value as get_version.
pub fn get_cmdline_args(&self) -> PackedArray<GString>
pub fn get_cmdline_args(&self) -> PackedArray<GString>
Returns the command-line arguments passed to the engine, excluding arguments processed by the engine, such as --headless and --fullscreen.
# Godot has been executed with the following command:
# godot --headless --verbose --scene my_scene.tscn --custom
OS.get_cmdline_args() # Returns ["--scene", "my_scene.tscn", "--custom"]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 get_environment method.
You can set [member ProjectSettings.editor/run/main_run_args] to define command-line arguments to be passed by the editor when running the project.
Example: Parse command-line arguments into a Dictionary using the --key=value form for arguments:
var arguments = {}
for argument in OS.get_cmdline_args():
if argument.contains("="):
var key_value = argument.split("=")
arguments[key_value[0].trim_prefix("--")] = key_value[1]
else:
# Options without an argument will be present in the dictionary,
# with the value set to an empty string.
arguments[argument.trim_prefix("--")] = ""Note: Passing custom user arguments directly is not recommended, as the engine may discard or modify them. Instead, pass the standard UNIX double dash (--) and then the custom arguments, which the engine will ignore by design. These can be read via get_cmdline_user_args.
pub fn get_cmdline_user_args(&self) -> PackedArray<GString>
pub fn get_cmdline_user_args(&self) -> PackedArray<GString>
Returns the command-line user arguments passed to the engine. User arguments are ignored by the engine and reserved for the user. They are passed after the double dash -- argument. ++ may be used when -- is intercepted by another program (such as startx).
# Godot has been executed with the following command:
# godot --fullscreen --custom -- --level=2 --hardcore
OS.get_cmdline_args() # Returns ["--custom"]
OS.get_cmdline_user_args() # Returns ["--level=2", "--hardcore"]To get arguments passed before -- or ++, use get_cmdline_args.
pub fn get_video_adapter_driver_info(&self) -> PackedArray<GString>
pub fn get_video_adapter_driver_info(&self) -> PackedArray<GString>
Returns the video adapter driver name and version for the user’s currently active graphics card, as a PackedStringArray. See also get_video_adapter_api_version.
The first element holds the driver name, such as nvidia, amdgpu, etc.
The second element holds the driver version. For example, on 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 Linux/BSD and Windows when not running in headless mode. On other platforms, it returns an empty array.
Note: This method will run slowly the first time it is called in a session; it can take several seconds depending on the operating system and hardware. It is blocking if called on the main thread, so it’s recommended to call it on a separate thread using Thread. This allows the engine to keep running while the information is being retrieved. However, get_video_adapter_driver_info is not thread-safe, so it should not be called from multiple threads at the same time.
var thread = Thread.new()
func _ready():
thread.start(
func():
var driver_info = OS.get_video_adapter_driver_info()
if not driver_info.is_empty():
print("Driver: %s %s" % [driver_info[0], driver_info[1]])
else:
print("Driver: (unknown)")
)
func _exit_tree():
thread.wait_to_finish()pub fn set_restart_on_exit(&mut self, restart: bool)
pub fn set_restart_on_exit(&mut self, restart: bool)
To set the default parameters, use set_restart_on_exit_ex and its builder methods. See the book for detailed usage instructions.
If restart is true, restarts the project automatically when it is exited with quit or NodeNotification::WM_CLOSE_REQUEST. Command-line arguments can be supplied. To restart the project with the same command line arguments as originally used to run the project, pass get_cmdline_args as the value for arguments.
This method can be used to apply setting changes that require a restart. See also is_restart_on_exit_set and get_restart_on_exit_arguments.
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.
pub fn set_restart_on_exit_ex<'ex>(
&'ex mut self,
restart: bool,
) -> ExSetRestartOnExit<'ex>
pub fn set_restart_on_exit_ex<'ex>( &'ex mut self, restart: bool, ) -> ExSetRestartOnExit<'ex>
If restart is true, restarts the project automatically when it is exited with quit or NodeNotification::WM_CLOSE_REQUEST. Command-line arguments can be supplied. To restart the project with the same command line arguments as originally used to run the project, pass get_cmdline_args as the value for arguments.
This method can be used to apply setting changes that require a restart. See also is_restart_on_exit_set and get_restart_on_exit_arguments.
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.
pub fn is_restart_on_exit_set(&self) -> bool
pub fn is_restart_on_exit_set(&self) -> bool
Returns true if the project will automatically restart when it exits for any reason, false otherwise. See also set_restart_on_exit and get_restart_on_exit_arguments.
pub fn get_restart_on_exit_arguments(&self) -> PackedArray<GString>
pub fn get_restart_on_exit_arguments(&self) -> PackedArray<GString>
Returns the list of command line arguments that will be used when the project automatically restarts using set_restart_on_exit. See also is_restart_on_exit_set.
pub fn delay_usec(&self, usec: i32)
pub fn delay_usec(&self, usec: i32)
Delays execution of the current thread by usec microseconds. usec must be greater than or equal to 0. Otherwise, delay_usec does nothing and prints an error message.
Note: delay_usec is a blocking way to delay code execution. To delay code execution in a non-blocking way, you may use create_timer. Awaiting with a SceneTreeTimer delays the execution of code placed below the await without affecting the rest of the project (or editor, for EditorPlugins and EditorScripts).
Note: When delay_usec 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 delay_usec 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).
pub fn delay_msec(&self, msec: i32)
pub fn delay_msec(&self, msec: i32)
Delays execution of the current thread by msec milliseconds. msec must be greater than or equal to 0. Otherwise, delay_msec does nothing and prints an error message.
Note: delay_msec is a blocking way to delay code execution. To delay code execution in a non-blocking way, you may use create_timer. Awaiting with SceneTreeTimer delays the execution of code placed below the await without affecting the rest of the project (or editor, for EditorPlugins and EditorScripts).
Note: When delay_msec 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 delay_msec 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).
pub fn get_locale(&self) -> GString
pub fn get_locale(&self) -> GString
Returns the host OS locale as a String of the form language_Script_COUNTRY_VARIANT@extra. Every substring after language is optional and may not exist.
-
language- 2 or 3-letter language code, in lower case. -
Script- 4-letter script code, in title case. -
COUNTRY- 2 or 3-letter country code, in upper case. -
VARIANT- language variant, region and sort order. The variant can have any number of underscored keywords. -
extra- semicolon separated list of additional key words. This may include currency, calendar, sort order and numbering system information.
If you want only the language code and not the fully specified locale from the OS, you can use get_locale_language.
pub fn get_locale_language(&self) -> GString
pub fn get_locale_language(&self) -> GString
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 get_locale 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.
pub fn get_model_name(&self) -> GString
pub fn get_model_name(&self) -> GString
Returns the model name of the current device.
Note: This method is implemented on Android, iOS, macOS, and Windows. Returns "GenericDevice" on unsupported platforms.
pub fn is_userfs_persistent(&self) -> bool
pub fn is_userfs_persistent(&self) -> bool
Returns true if the user:// file system is persistent, that is, 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.
pub fn is_stdout_verbose(&self) -> bool
pub fn is_stdout_verbose(&self) -> bool
Returns true if the engine was executed with the --verbose or -v command line argument, or if [member ProjectSettings.debug/settings/stdout/verbose_stdout] is true. See also print_verbose.
pub fn is_debug_build(&self) -> bool
pub fn is_debug_build(&self) -> bool
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.
Note: To check whether the Godot binary used to run the project is an export template (debug or release), use OS.has_feature("template") instead.
pub fn get_static_memory_usage(&self) -> u64
pub fn get_static_memory_usage(&self) -> u64
Returns the amount of static memory being used by the program in bytes. Only works in debug builds.
pub fn get_static_memory_peak_usage(&self) -> u64
pub fn get_static_memory_peak_usage(&self) -> u64
Returns the maximum amount of static memory used. Only works in debug builds.
pub fn get_memory_info(&self) -> Dictionary<Variant, Variant>
pub fn get_memory_info(&self) -> Dictionary<Variant, Variant>
Returns a Dictionary containing information about the current memory with the following entries:
-
"physical"- total amount of usable physical memory in bytes. This value can be slightly less than the actual physical memory amount, since it does not include memory reserved by the kernel and devices. -
"free"- amount of physical memory, that can be immediately allocated without disk access or other costly operations, in bytes. The process might be able to allocate more physical memory, but this action will require moving inactive pages to disk, which can be expensive. -
"available"- amount of memory that can be allocated without extending the swap file(s), in bytes. This value includes both physical memory and swap. -
"stack"- size of the current thread stack in bytes.
Note: Each entry’s value may be -1 if it is unknown.
pub fn move_to_trash(&self, path: impl AsArg<GString>) -> Error
pub fn move_to_trash(&self, path: impl AsArg<GString>) -> Error
Moves the file or directory at the given path to the system’s recycle bin. See also remove.
The method takes only global paths, so you may need to use globalize_path. Do not use it for files in res:// as it will not work in exported projects.
Returns Error::FAILED if the file or directory cannot be found, or the system does not support this method.
var file_to_remove = "user://slot1.save"
OS.move_to_trash(ProjectSettings.globalize_path(file_to_remove))Note: This method is implemented on Android, Linux, macOS and Windows.
Note: If the user has disabled the recycle bin on their system, the file will be permanently deleted instead.
pub fn get_user_data_dir(&self) -> GString
pub fn get_user_data_dir(&self) -> GString
Returns the absolute directory path where user data is written (the user:// directory in Godot). The path depends on the project name and [member ProjectSettings.application/config/use_custom_user_dir].
-
On Windows, this is
%AppData%\Godot\app_userdata\[project_name], or%AppData%\[custom_name]ifuse_custom_user_diris 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]ifuse_custom_user_diris set. -
On Linux and BSD, this is
~/.local/share/godot/app_userdata/[project_name], or~/.local/share/[custom_name]ifuse_custom_user_diris set. -
On Android and iOS, this is a sandboxed directory in either internal or external storage, depending on the user’s configuration.
-
On 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 get_data_dir, which returns the global (non-project-specific) user home directory.
pub fn get_system_dir(&self, dir: SystemDir) -> GString
pub fn get_system_dir(&self, dir: SystemDir) -> GString
To set the default parameters, use get_system_dir_ex and its builder methods. See the book for detailed usage instructions.
Returns the path to commonly used folders across different platforms, as defined by dir. See the [enum SystemDir] constants for available locations.
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, if shared_storage is true. Shared directories have additional restrictions on Android.
pub fn get_system_dir_ex<'ex>(&'ex self, dir: SystemDir) -> ExGetSystemDir<'ex>
pub fn get_system_dir_ex<'ex>(&'ex self, dir: SystemDir) -> ExGetSystemDir<'ex>
Returns the path to commonly used folders across different platforms, as defined by dir. See the [enum SystemDir] constants for available locations.
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, if shared_storage is true. Shared directories have additional restrictions on Android.
pub fn get_config_dir(&self) -> GString
pub fn get_config_dir(&self) -> GString
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 get_cache_dir and get_data_dir.
Not to be confused with get_user_data_dir, which returns the project-specific user data path.
pub fn get_data_dir(&self) -> GString
pub fn get_data_dir(&self) -> GString
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 get_cache_dir and get_config_dir.
Not to be confused with get_user_data_dir, which returns the project-specific user data path.
pub fn get_cache_dir(&self) -> GString
pub fn get_cache_dir(&self) -> GString
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 get_config_dir and get_data_dir.
Not to be confused with get_user_data_dir, which returns the project-specific user data path.
pub fn get_temp_dir(&self) -> GString
pub fn get_temp_dir(&self) -> GString
Returns the global temporary data directory according to the operating system’s standards.
pub fn get_unique_id(&self) -> GString
pub fn get_unique_id(&self) -> GString
Returns a string that is unique to the device.
Note: This string may change without notice if the user reinstalls their operating system, upgrades it, or modifies 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 this method for security purposes.
Note: On Web, returns an empty string and generates an error, as this method cannot be implemented for security reasons.
pub fn get_keycode_string(&self, code: Key) -> GString
pub fn get_keycode_string(&self, code: Key) -> GString
Returns the given keycode as a String.
print(OS.get_keycode_string(KEY_C)) # Prints "C"
print(OS.get_keycode_string(KEY_ESCAPE)) # Prints "Escape"
print(OS.get_keycode_string(KEY_MASK_SHIFT | KEY_TAB)) # Prints "Shift+Tab"See also find_keycode_from_string, [member InputEventKey.keycode], and get_keycode_with_modifiers.
pub fn is_keycode_unicode(&self, code: u32) -> bool
pub fn is_keycode_unicode(&self, code: u32) -> bool
Returns true if the input keycode corresponds to a Unicode character. For a list of codes, see the [enum Key] constants.
print(OS.is_keycode_unicode(KEY_G)) # Prints true
print(OS.is_keycode_unicode(KEY_KP_4)) # Prints true
print(OS.is_keycode_unicode(KEY_TAB)) # Prints false
print(OS.is_keycode_unicode(KEY_ESCAPE)) # Prints falsepub fn find_keycode_from_string(&self, string: impl AsArg<GString>) -> Key
pub fn find_keycode_from_string(&self, string: impl AsArg<GString>) -> Key
Finds the keycode for the given string. The returned values are equivalent to the [enum Key] constants.
print(OS.find_keycode_from_string("C")) # Prints 67 (KEY_C)
print(OS.find_keycode_from_string("Escape")) # Prints 4194305 (KEY_ESCAPE)
print(OS.find_keycode_from_string("Shift+Tab")) # Prints 37748738 (KEY_MASK_SHIFT | KEY_TAB)
print(OS.find_keycode_from_string("Unknown")) # Prints 0 (KEY_NONE)See also get_keycode_string.
pub fn set_use_file_access_save_and_swap(&mut self, enabled: bool)
pub fn set_use_file_access_save_and_swap(&mut self, enabled: bool)
If enabled is true, when opening a file for writing, a temporary file is used in its place. When closed, it is automatically applied to the target file.
This can useful when files may be opened by other applications, such as antiviruses, text editors, or even the Godot editor itself.
pub fn set_thread_name(&mut self, name: impl AsArg<GString>) -> Error
pub fn set_thread_name(&mut self, name: impl AsArg<GString>) -> Error
Assigns the given name to the current thread. Returns Error::ERR_UNAVAILABLE if unavailable on the current platform.
pub fn get_thread_caller_id(&self) -> u64
pub fn get_thread_caller_id(&self) -> u64
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.
pub fn get_main_thread_id(&self) -> u64
pub fn get_main_thread_id(&self) -> u64
Returns the ID of the main thread. See get_thread_caller_id.
Note: Thread IDs are not deterministic and may be reused across application restarts.
pub fn has_feature(&self, tag_name: impl AsArg<GString>) -> bool
pub fn has_feature(&self, tag_name: impl AsArg<GString>) -> 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.
Note: Tag names are case-sensitive.
Note: On the Web platform, one of the following additional tags is defined to indicate the host platform: web_android, web_ios, web_linuxbsd, web_macos, or web_windows.
pub fn is_sandboxed(&self) -> bool
pub fn is_sandboxed(&self) -> bool
Returns true if the application is running in the sandbox.
Note: This method is only implemented on macOS and Linux.
pub fn request_permission(&mut self, name: impl AsArg<GString>) -> bool
pub fn request_permission(&mut self, name: impl AsArg<GString>) -> bool
Requests permission from the OS for the given name. Returns true if the permission has already been granted. See also MainLoop.on_request_permissions_result.
The name must be the full permission name. For example:
-
OS.request_permission("android.permission.READ_EXTERNAL_STORAGE") -
OS.request_permission("android.permission.POST_NOTIFICATIONS") -
OS.request_permission("macos.permission.RECORD_SCREEN") -
OS.request_permission("appleembedded.permission.AUDIO_RECORD")
Note: On Android, permission must be checked during export.
Note: This method is implemented on Android, macOS, and visionOS platforms.
pub fn request_permissions(&mut self) -> bool
pub fn request_permissions(&mut self) -> bool
Requests dangerous permissions from the OS. Returns true if permissions have already been granted. See also MainLoop.on_request_permissions_result.
Note: Permissions must be checked during export.
Note: This method is only implemented on Android. Normal permissions are automatically granted at install time in Android applications.
pub fn get_granted_permissions(&self) -> PackedArray<GString>
pub fn get_granted_permissions(&self) -> PackedArray<GString>
On Android devices: Returns the list of dangerous permissions that have been granted.
On macOS: Returns the list of granted permissions and user selected folders accessible to the application (sandboxed applications only). Use the native file dialog to request folder access permission.
On iOS, visionOS: Returns the list of granted permissions.
pub fn revoke_granted_permissions(&mut self)
pub fn revoke_granted_permissions(&mut self)
On macOS (sandboxed applications only), this function clears list of user selected folders accessible to the application.
pub fn add_logger(&mut self, logger: impl AsArg<Option<Gd<Logger>>>)
pub fn add_logger(&mut self, logger: impl AsArg<Option<Gd<Logger>>>)
Add a custom logger to intercept the internal message stream.
pub fn remove_logger(&mut self, logger: impl AsArg<Option<Gd<Logger>>>)
pub fn remove_logger(&mut self, logger: impl AsArg<Option<Gd<Logger>>>)
Remove a custom logger added by add_logger.
Methods from Deref<Target = Object>§
pub fn get_script(&self) -> Option<Gd<Script>>
pub fn set_script(&mut self, script: impl AsArg<Option<Gd<Script>>>)
pub fn connect( &mut self, signal: impl AsArg<StringName>, callable: &Callable, ) -> Error
pub fn connect_flags( &mut self, signal: impl AsArg<StringName>, callable: &Callable, flags: ConnectFlags, ) -> Error
pub fn is_class(&self, class: impl AsArg<GString>) -> bool
pub fn is_class(&self, class: impl AsArg<GString>) -> bool
Returns true if the object inherits from the given class. See also get_class.
var sprite2d = Sprite2D.new()
sprite2d.is_class("Sprite2D") # Returns true
sprite2d.is_class("Node") # Returns true
sprite2d.is_class("Node3D") # Returns falseNote: This method ignores class_name declarations in the object’s script.
pub fn set(&mut self, property: impl AsArg<StringName>, value: &Variant)
pub fn set(&mut self, property: impl AsArg<StringName>, value: &Variant)
Assigns value to the given property. If the property does not exist or the given value’s type doesn’t match, nothing happens.
var node = Node2D.new()
node.set("global_scale", Vector2(8, 2.5))
print(node.global_scale) # Prints (8.0, 2.5)Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn get(&self, property: impl AsArg<StringName>) -> Variant
pub fn get(&self, property: impl AsArg<StringName>) -> Variant
Returns the Variant value of the given property. If the property does not exist, this method returns null.
var node = Node2D.new()
node.rotation = 1.5
var a = node.get("rotation") # a is 1.5Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn set_indexed(
&mut self,
property_path: impl AsArg<NodePath>,
value: &Variant,
)
pub fn set_indexed( &mut self, property_path: impl AsArg<NodePath>, value: &Variant, )
Assigns a new value to the property identified by the property_path. The path should be a NodePath relative to this object, and can use the colon character (:) to access nested properties.
var node = Node2D.new()
node.set_indexed("position", Vector2(42, 0))
node.set_indexed("position:y", -10)
print(node.position) # Prints (42.0, -10.0)Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn get_indexed(&self, property_path: impl AsArg<NodePath>) -> Variant
pub fn get_indexed(&self, property_path: impl AsArg<NodePath>) -> Variant
Gets the object’s property indexed by the given property_path. The path should be a NodePath relative to the current object and can use the colon character (:) to access nested properties.
Examples: "position:x" or "material:next_pass:blend_mode".
var node = Node2D.new()
node.position = Vector2(5, -10)
var a = node.get_indexed("position") # a is Vector2(5, -10)
var b = node.get_indexed("position:y") # b is -10Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
Note: This method does not support actual paths to nodes in the SceneTree, only sub-property paths. In the context of nodes, use get_node_and_resource instead.
pub fn get_property_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_property_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns the object’s property list as an Array of dictionaries. Each Dictionary contains the following entries:
-
nameis the property’s name, as aString; -
class_nameis an emptyStringName, unless the property isVariantType::OBJECTand it inherits from a class; -
typeis the property’s type, as anint(see [enum Variant.Type]); -
hintis how the property is meant to be edited (see [enum PropertyHint]); -
hint_stringdepends on the hint (see [enum PropertyHint]); -
usageis a combination of [enum PropertyUsageFlags].
Note: In GDScript, all class members are treated as properties. In C# and GDExtension, it may be necessary to explicitly mark class members as Godot properties using decorators or attributes.
pub fn get_method_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_method_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns this object’s methods and their signatures as an Array of dictionaries. Each Dictionary contains the following entries:
-
nameis the name of the method, as aString; -
argsis anArrayof dictionaries representing the arguments; -
default_argsis the default arguments as anArrayof variants; -
flagsis a combination of [enum MethodFlags]; -
idis the method’s internal identifierint; -
returnis the returned value, as aDictionary;
Note: The dictionaries of args and return are formatted identically to the results of get_property_list, although not all entries are used.
pub fn property_can_revert(&self, property: impl AsArg<StringName>) -> bool
pub fn property_can_revert(&self, property: impl AsArg<StringName>) -> bool
Returns true if the given property has a custom default value. Use property_get_revert to get the property’s default value.
Note: This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_can_revert] to customize the default value. If [method _property_can_revert] is not implemented, this method returns false.
pub fn property_get_revert(&self, property: impl AsArg<StringName>) -> Variant
pub fn property_get_revert(&self, property: impl AsArg<StringName>) -> Variant
Returns the custom default value of the given property. Use property_can_revert to check if the property has a custom default value.
Note: This method is used by the Inspector dock to display a revert icon. The object must implement [method _property_get_revert] to customize the default value. If [method _property_get_revert] is not implemented, this method returns null.
pub fn set_meta(&mut self, name: impl AsArg<StringName>, value: &Variant)
pub fn set_meta(&mut self, name: impl AsArg<StringName>, value: &Variant)
Adds or changes the entry name inside the object’s metadata. The metadata value can be any Variant, although some types cannot be serialized correctly.
If value is null, the entry is removed. This is the equivalent of using remove_meta. See also has_meta and get_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn remove_meta(&mut self, name: impl AsArg<StringName>)
pub fn remove_meta(&mut self, name: impl AsArg<StringName>)
Removes the given entry name from the object’s metadata. See also has_meta, get_meta and set_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta(&self, name: impl AsArg<StringName>) -> Variant
pub fn get_meta(&self, name: impl AsArg<StringName>) -> Variant
To set the default parameters, use get_meta_ex and its builder methods. See the book for detailed usage instructions.
Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta_ex<'ex>(
&'ex self,
name: impl AsArg<StringName> + 'ex,
) -> ExGetMeta<'ex>
pub fn get_meta_ex<'ex>( &'ex self, name: impl AsArg<StringName> + 'ex, ) -> ExGetMeta<'ex>
Returns the object’s metadata value for the given entry name. If the entry does not exist, returns default. If default is null, an error is also generated.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn has_meta(&self, name: impl AsArg<StringName>) -> bool
pub fn has_meta(&self, name: impl AsArg<StringName>) -> bool
Returns true if a metadata entry is found with the given name. See also get_meta, set_meta and remove_meta.
Note: A metadata’s name must be a valid identifier as per is_valid_identifier method.
Note: Metadata that has a name starting with an underscore (_) is considered editor-only. Editor-only metadata is not displayed in the Inspector and should not be edited, although it can still be found by this method.
pub fn get_meta_list(&self) -> Array<StringName>
pub fn get_meta_list(&self) -> Array<StringName>
Returns the object’s metadata entry names as an Array of StringNames.
pub fn add_user_signal(&mut self, signal: impl AsArg<GString>)
pub fn add_user_signal(&mut self, signal: impl AsArg<GString>)
To set the default parameters, use add_user_signal_ex and its builder methods. See the book for detailed usage instructions.
Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see [enum Variant.Type]). See also has_user_signal and remove_user_signal.
add_user_signal("hurt", [
{ "name": "damage", "type": TYPE_INT },
{ "name": "source", "type": TYPE_OBJECT }
])pub fn add_user_signal_ex<'ex>(
&'ex mut self,
signal: impl AsArg<GString> + 'ex,
) -> ExAddUserSignal<'ex>
pub fn add_user_signal_ex<'ex>( &'ex mut self, signal: impl AsArg<GString> + 'ex, ) -> ExAddUserSignal<'ex>
Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see [enum Variant.Type]). See also has_user_signal and remove_user_signal.
add_user_signal("hurt", [
{ "name": "damage", "type": TYPE_INT },
{ "name": "source", "type": TYPE_OBJECT }
])pub fn has_user_signal(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_user_signal(&self, signal: impl AsArg<StringName>) -> bool
Returns true if the given user-defined signal name exists. Only signals added with add_user_signal are included. See also remove_user_signal.
pub fn remove_user_signal(&mut self, signal: impl AsArg<StringName>)
pub fn remove_user_signal(&mut self, signal: impl AsArg<StringName>)
Removes the given user signal signal from the object. See also add_user_signal and has_user_signal.
pub fn emit_signal(
&mut self,
signal: impl AsArg<StringName>,
varargs: &[Variant],
) -> Error
pub fn emit_signal( &mut self, signal: impl AsArg<StringName>, varargs: &[Variant], ) -> Error
Emits the given signal by name. The signal must exist, so it should be a built-in signal of this class or one of its inherited classes, or a user-defined signal (see add_user_signal). This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
Returns Error::ERR_UNAVAILABLE if signal does not exist or the parameters are invalid.
emit_signal("hit", "sword", 100)
emit_signal("game_over")Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_emit_signal(
&mut self,
signal: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Error, CallError>
pub fn try_emit_signal( &mut self, signal: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Error, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn call(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Variant
pub fn call( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Variant
Calls the method on the object and returns the result. This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
var node = Node3D.new()
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_call(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Variant, CallError>
pub fn try_call( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Variant, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn call_deferred(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Variant
pub fn call_deferred( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Variant
Calls the method on the object during idle time. Always returns null, not the method’s result.
Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they’ll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.
This method supports a variable number of arguments, so parameters can be passed as a comma separated list.
var node = Node3D.new()
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)For methods that are deferred from the same thread, the order of execution at idle time is identical to the order in which call_deferred was called.
See also call_deferred.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
Note: If you’re looking to delay the function call by a frame, refer to the SceneTree.process_frame and SceneTree.physics_frame signals.
var node = Node3D.new()
# Make a Callable and bind the arguments to the node's rotate() call.
var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
# Connect the callable to the process_frame signal, so it gets called in the next process frame.
# CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)§Panics
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will panic in such a case.
pub fn try_call_deferred(
&mut self,
method: impl AsArg<StringName>,
varargs: &[Variant],
) -> Result<Variant, CallError>
pub fn try_call_deferred( &mut self, method: impl AsArg<StringName>, varargs: &[Variant], ) -> Result<Variant, CallError>
§Return type
This is a varcall method, meaning parameters and return values are passed as Variant.
It can detect call failures and will return Err in such a case.
pub fn set_deferred(
&mut self,
property: impl AsArg<StringName>,
value: &Variant,
)
pub fn set_deferred( &mut self, property: impl AsArg<StringName>, value: &Variant, )
Assigns value to the given property, at the end of the current frame. This is equivalent to calling set through call_deferred.
var node = Node2D.new()
add_child(node)
node.rotation = 1.5
node.set_deferred("rotation", 3.0)
print(node.rotation) # Prints 1.5
await get_tree().process_frame
print(node.rotation) # Prints 3.0Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.
pub fn callv(
&mut self,
method: impl AsArg<StringName>,
arg_array: &AnyArray,
) -> Variant
pub fn callv( &mut self, method: impl AsArg<StringName>, arg_array: &AnyArray, ) -> Variant
Calls the method on the object and returns the result. Unlike call, this method expects all parameters to be contained inside arg_array.
var node = Node3D.new()
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn has_method(&self, method: impl AsArg<StringName>) -> bool
pub fn has_method(&self, method: impl AsArg<StringName>) -> bool
Returns true if the given method name exists in the object.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn get_method_argument_count(&self, method: impl AsArg<StringName>) -> i32
pub fn get_method_argument_count(&self, method: impl AsArg<StringName>) -> i32
Returns the number of arguments of the given method by name.
Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.
pub fn has_signal(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_signal(&self, signal: impl AsArg<StringName>) -> bool
Returns true if the given signal name exists in the object.
Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn get_signal_list(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_signal_list(&self) -> Array<Dictionary<Variant, Variant>>
Returns the list of existing signals as an Array of dictionaries.
Note: Due to the implementation, each Dictionary is formatted very similarly to the returned values of get_method_list.
pub fn get_signal_connection_list(
&self,
signal: impl AsArg<StringName>,
) -> Array<Dictionary<Variant, Variant>>
pub fn get_signal_connection_list( &self, signal: impl AsArg<StringName>, ) -> Array<Dictionary<Variant, Variant>>
Returns an Array of connections for the given signal name. Each connection is represented as a Dictionary that contains three entries:
pub fn get_incoming_connections(&self) -> Array<Dictionary<Variant, Variant>>
pub fn get_incoming_connections(&self) -> Array<Dictionary<Variant, Variant>>
Returns an Array of signal connections received by this object. Each connection is represented as a Dictionary that contains three entries:
pub fn disconnect(
&mut self,
signal: impl AsArg<StringName>,
callable: &Callable,
)
pub fn disconnect( &mut self, signal: impl AsArg<StringName>, callable: &Callable, )
Disconnects a signal by name from a given callable. If the connection does not exist, generates an error. Use is_connected to make sure that the connection exists.
pub fn is_connected(
&self,
signal: impl AsArg<StringName>,
callable: &Callable,
) -> bool
pub fn is_connected( &self, signal: impl AsArg<StringName>, callable: &Callable, ) -> bool
Returns true if a connection exists between the given signal name and callable.
Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn has_connections(&self, signal: impl AsArg<StringName>) -> bool
pub fn has_connections(&self, signal: impl AsArg<StringName>) -> bool
Returns true if any connection exists on the given signal name.
Note: In C#, signal must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.
pub fn set_block_signals(&mut self, enable: bool)
pub fn set_block_signals(&mut self, enable: bool)
If set to true, the object becomes unable to emit signals. As such, emit_signal and signal connections will not work, until it is set to false.
pub fn is_blocking_signals(&self) -> bool
pub fn is_blocking_signals(&self) -> bool
Returns true if the object is blocking its signals from being emitted. See set_block_signals.
pub fn notify_property_list_changed(&mut self)
pub fn notify_property_list_changed(&mut self)
Emits the property_list_changed signal. This is mainly used to refresh the editor, so that the Inspector and editor plugins are properly updated.
pub fn set_message_translation(&mut self, enable: bool)
pub fn set_message_translation(&mut self, enable: bool)
If set to true, allows the object to translate messages with tr and tr_n. Enabled by default. See also can_translate_messages.
pub fn can_translate_messages(&self) -> bool
pub fn can_translate_messages(&self) -> bool
Returns true if the object is allowed to translate messages with tr and tr_n. See also set_message_translation.
pub fn tr(&self, message: impl AsArg<StringName>) -> GString
pub fn tr(&self, message: impl AsArg<StringName>) -> GString
To set the default parameters, use tr_ex and its builder methods. See the book for detailed usage instructions.
Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.
For detailed examples, see Internationalizing games.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate.
pub fn tr_ex<'ex>(&'ex self, message: impl AsArg<StringName> + 'ex) -> ExTr<'ex>
pub fn tr_ex<'ex>(&'ex self, message: impl AsArg<StringName> + 'ex) -> ExTr<'ex>
Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.
If can_translate_messages is false, or no translation is available, this method returns the message without changes. See set_message_translation.
For detailed examples, see Internationalizing games.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate.
pub fn tr_n(
&self,
message: impl AsArg<StringName>,
plural_message: impl AsArg<StringName>,
n: i32,
) -> GString
pub fn tr_n( &self, message: impl AsArg<StringName>, plural_message: impl AsArg<StringName>, n: i32, ) -> GString
To set the default parameters, use tr_n_ex and its builder methods. See the book for detailed usage instructions.
Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.
The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended to handle these cases with tr.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate_plural.
pub fn tr_n_ex<'ex>(
&'ex self,
message: impl AsArg<StringName> + 'ex,
plural_message: impl AsArg<StringName> + 'ex,
n: i32,
) -> ExTrN<'ex>
pub fn tr_n_ex<'ex>( &'ex self, message: impl AsArg<StringName> + 'ex, plural_message: impl AsArg<StringName> + 'ex, n: i32, ) -> ExTrN<'ex>
Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.
If can_translate_messages is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation.
The n is the number, or amount, of the message’s subject. It is used by the translation system to fetch the correct plural form for the current language.
For detailed examples, see Localization using gettext.
Note: Negative and float numbers may not properly apply to some countable subjects. It’s recommended to handle these cases with tr.
Note: This method can’t be used without an Object instance, as it requires the can_translate_messages method. To translate strings in a static context, use translate_plural.
pub fn get_translation_domain(&self) -> StringName
pub fn get_translation_domain(&self) -> StringName
Returns the name of the translation domain used by tr and tr_n. See also TranslationServer.
pub fn set_translation_domain(&mut self, domain: impl AsArg<StringName>)
pub fn set_translation_domain(&mut self, domain: impl AsArg<StringName>)
Sets the name of the translation domain used by tr and tr_n. See also TranslationServer.
pub fn is_queued_for_deletion(&self) -> bool
pub fn is_queued_for_deletion(&self) -> bool
Returns true if the queue_free method was called for the object.
pub fn cancel_free(&mut self)
pub fn cancel_free(&mut self)
If this method is called during ObjectNotification::PREDELETE, this object will reject being freed and will remain allocated. This is mostly an internal function used for error handling to avoid the user from freeing objects when they are not intended to.
pub fn notify(&mut self, what: ObjectNotification)
pub fn notify(&mut self, what: ObjectNotification)
⚠️ Sends a Godot notification to all classes inherited by the object.
Triggers calls to on_notification(), and depending on the notification, also to Godot’s lifecycle callbacks such as ready().
Starts from the highest ancestor (the Object class) and goes down the hierarchy.
See also Godot docs for Object::notification().
§Panics
If you call this method on a user-defined object while holding a GdRef or GdMut guard on the instance, you will encounter
a panic. The reason is that the receiving virtual method on_notification() acquires a GdMut lock dynamically, which must
be exclusive.
pub fn notify_reversed(&mut self, what: ObjectNotification)
pub fn notify_reversed(&mut self, what: ObjectNotification)
⚠️ Like Self::notify(), but starts at the most-derived class and goes up the hierarchy.
See docs of that method, including the panics.
Trait Implementations§
§impl GodotClass for Os
impl GodotClass for Os
§const INIT_LEVEL: InitLevel = crate::init::InitLevel::Core
const INIT_LEVEL: InitLevel = crate::init::InitLevel::Core
§fn class_id() -> ClassId
fn class_id() -> ClassId
§fn inherits<Base>() -> boolwhere
Base: GodotClass,
fn inherits<Base>() -> boolwhere
Base: GodotClass,
§impl WithSignals for Os
impl WithSignals for Os
§type SignalCollection<'c, C: WithSignals> = SignalsOfObject<'c, C>
type SignalCollection<'c, C: WithSignals> = SignalsOfObject<'c, C>
Auto Trait Implementations§
impl Freeze for Os
impl RefUnwindSafe for Os
impl !Send for Os
impl !Sync for Os
impl Unpin for Os
impl UnsafeUnpin for Os
impl UnwindSafe for Os
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Inherits<T> for Twhere
T: GodotClass,
impl<T> Inherits<T> for Twhere
T: GodotClass,
§const IS_SAME_CLASS: bool = true
const IS_SAME_CLASS: bool = true
Self == Base. Read more