A list of GDScript-specific utility functions and annotations accessible from any script.
For the list of the global functions and constants see @GlobalScope.
Returns a Color constructed from red (r8), green (g8), blue (b8), and optionally alpha (a8) integer channels, each divided by 255.0 for their final value. Using Color8 instead of the standard Color constructor is useful when you need to match exact color values in an Image.
Note: Due to the lower precision of Color8 compared to the standard Color constructor, a color created with Color8 will generally not be equal to the same color created with the standard Color constructor. Use Color.is_equal_approx for comparisons to avoid issues with floating-point precision error.
Asserts that the condition is true. If the condition is false, an error is generated. When running from the editor, the running project will also be paused until you resume it. This can be used as a stronger form of @GlobalScope.push_error for reporting errors to project developers or add-on users.
An optional message can be shown in addition to the generic "Assertion failed" message. You can use this to provide additional details about why the assertion failed.
Warning: For performance reasons, the code inside assert is only executed in debug builds or when running the project from the editor. Don't include code that has side effects in an assert call. Otherwise, the project will behave differently when exported in release mode.
Returns a single character (as a String) of the given Unicode code point (which is compatible with ASCII code).
Deprecated. Use @GlobalScope.type_convert instead.
Converts what to type in the best way possible. The type uses the Variant.Type values.
Converts a dictionary (created with inst_to_dict) back to an Object instance. Can be useful for deserializing.
Returns an array of dictionaries representing the current call stack. See also print_stack.
Starting from _ready(), bar() would print:
Note: This function only works if the running instance is connected to a debugging server (i.e. an editor instance). get_stack will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
Note: Calling this function from a Thread is not supported. Doing so will return an empty array.
Returns the passed instance converted to a Dictionary. Can be useful for serializing.
Note: Cannot be used to serialize objects with built-in scripts attached or objects allocated within built-in scripts.
Prints out:
Returns true if value is an instance of type. The type value must be one of the following:
A constant from the Variant.Type enumeration, for example @GlobalScope.TYPE_INT.
An Object-derived class which exists in ClassDB, for example Node.
A Script (you can use any class, including inner one).
Unlike the right operand of the is operator, type can be a non-constant value. The is operator supports more features (such as typed arrays) and is more performant. Use the operator instead of this method if you do not need dynamic type checking.
Examples:
Note: If value and/or type are freed objects (see @GlobalScope.is_instance_valid), or type is not one of the above options, this method will raise a runtime error.
See also @GlobalScope.typeof, type_exists, Array.is_same_typed (and other Array methods).
Returns the length of the given Variant var. The length can be the character count of a String or StringName, the element count of any array type, or the size of a Dictionary. For every other Variant type, a run-time error is generated and execution is stopped.
Returns a Resource from the filesystem located at the absolute path. Unless it's already referenced elsewhere (such as in another script or in the scene), the resource is loaded from disk on function call, which might cause a slight delay, especially when loading large scenes. To avoid unnecessary delays when loading something multiple times, either store the resource in a variable or use preload. This method is equivalent of using ResourceLoader.load with ResourceLoader.CACHE_MODE_REUSE.
Note: Resource paths can be obtained by right-clicking on a resource in the FileSystem dock and choosing "Copy Path", or by dragging the file from the FileSystem dock into the current script.
Important: The path must be absolute. A relative path will always return null.
This function is a simplified version of ResourceLoader.load, which can be used for more advanced scenarios.
Note: Files have to be imported into the engine first to load them using this function. If you want to load Images at run-time, you may use Image.load. If you want to import audio files, you can use the snippet described in AudioStreamMP3.data.
Note: If ProjectSettings.editor/export/convert_text_resources_to_binary is true, load will not be able to read converted files in an exported project. If you rely on run-time loading of files present within the PCK, set ProjectSettings.editor/export/convert_text_resources_to_binary to false.
Returns a Resource from the filesystem located at path. During run-time, the resource is loaded when the script is being parsed. This function effectively acts as a reference to that resource. Note that this function requires path to be a constant String. If you want to load a resource from a dynamic/variable path, use load.
Note: Resource paths can be obtained by right-clicking on a resource in the Assets Panel and choosing "Copy Path", or by dragging the file from the FileSystem dock into the current script.
Like @GlobalScope.print, but includes the current stack frame when running with the debugger turned on.
The output in the console may look like the following:
Note: Calling this function from a Thread is not supported. Doing so will instead print the thread ID.
Prints a stack trace at the current code location. See also get_stack.
The output in the console may look like the following:
Note: This function only works if the running instance is connected to a debugging server (i.e. an editor instance). print_stack will not work in projects exported in release mode, or in projects exported in debug mode if not connected to a debugging server.
Note: Calling this function from a Thread is not supported. Doing so will instead print the thread ID.
Returns an array with the given range. range can be called in three ways:
range(n: int): Starts from 0, increases by steps of 1, and stops before n. The argument n is exclusive.
range(b: int, n: int): Starts from b, increases by steps of 1, and stops before n. The arguments b and n are inclusive and exclusive, respectively.
range(b: int, n: int, s: int): Starts from b, increases/decreases by steps of s, and stops before n. The arguments b and n are inclusive and exclusive, respectively. The argument s can be negative, but not 0. If s is 0, an error message is printed.
range converts all arguments to int before processing.
Note: Returns an empty array if no value meets the value constraint (e.g. range(2, 5, -1) or range(5, 5, 1)).
Examples:
To iterate over an Array backwards, use:
Output:
To iterate over float, convert them in the loop.
Output:
Returns true if the given Object-derived class exists in ClassDB. Note that Variant data types are not registered in ClassDB.







