Skip to main content

Module global

Module global 

Expand description

Godot global enums, constants and utility functions.

See also Godot docs for @GlobalScope.

§Functions moved to dedicated APIs

Some methods in @GlobalScope are not directly available in godot::global module, but rather in their related types.
You can find them as follows:

Godot utility functiongodot-rust APIs
instance_from_idGd::from_instance_id()
Gd::try_from_instance_id()
is_instance_validGd::is_instance_valid()
is_instance_id_validInstanceId::lookup_validity()

§Global enums in other modules

The library ships several additional enums in places where GDScript would use magic numbers. These are co-located with builtin types, in the godot::builtin module. The enums are:

Some enums are closely related to property/method registration and are located in godot::register::info:

Macros§

godot_error
Pushes an error message to Godot’s built-in debugger and to the OS terminal.
godot_print
Prints to the Godot console.
godot_print_rich
Prints to the Godot console. Supports BBCode, color and URL tags.
godot_script_error
Logs a script error to Godot’s built-in debugger and to the OS terminal.
godot_str
Concatenates format-style arguments into a GString.
godot_warn
Pushes a warning message to Godot’s built-in debugger and to the OS terminal.

Structs§

Error
HorizontalAlignment
InlineAlignment
JoyAxis
JoyButton
Key
KeyLocation
KeyModifierMask
MidiMessage
Godot enum name: MIDIMessage.
MouseButton
MouseButtonMask
PrintRecord
Log record passed to print_custom().
PrintSource
Source location associated with a PrintRecord.
VerticalAlignment

Enums§

ClockDirection
This enum is exhaustive; you should not expect future Godot versions to add new enumerators.
Orientation
This enum is exhaustive; you should not expect future Godot versions to add new enumerators.
PrintLevel
Severity level for print_custom().

Functions§

abs
Returns the absolute value of a Variant parameter x (i.e. non-negative value). Supported types: int, float, Vector2, Vector2i, Vector3, Vector3i, Vector4, Vector4i.
absf
Returns the absolute value of float parameter x (i.e. positive value).
absi
Returns the absolute value of int parameter x (i.e. positive value).
acos
Returns the arc cosine of x in radians. Use to get the angle of cosine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent [method acos] from returning @GDScript.NAN.
acosh
Returns the hyperbolic arc (also called inverse) cosine of x, returning a value in radians. Use it to get the angle from an angle’s cosine in hyperbolic space if x is larger or equal to 1. For values of x lower than 1, it will return 0, in order to prevent [method acosh] from returning @GDScript.NAN.
angle_difference
Returns the difference between the two angles (in radians), in the range of [-PI, +PI]. When from and to are opposite, returns -PI if from is smaller than to, or PI otherwise.
asin
Returns the arc sine of x in radians. Use to get the angle of sine x. x will be clamped between -1.0 and 1.0 (inclusive), in order to prevent [method asin] from returning @GDScript.NAN.
asinh
Returns the hyperbolic arc (also called inverse) sine of x, returning a value in radians. Use it to get the angle from an angle’s sine in hyperbolic space.
atan
Returns the arc tangent of x in radians. Use it to get the angle from an angle’s tangent in trigonometry.
atan2
Returns the arc tangent of y/x in radians. Use to get the angle of tangent y/x. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant.
atanh
Returns the hyperbolic arc (also called inverse) tangent of x, returning a value in radians. Use it to get the angle from an angle’s tangent in hyperbolic space if x is between -1 and 1 (non-inclusive).
bezier_derivative
Returns the derivative at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.
bezier_interpolate
Returns the point at the given t on a one-dimensional Bézier curve defined by the given control_1, control_2, and end points.
bytes_to_var
Decodes a byte array back to a Variant value, without decoding objects.
bytes_to_var_with_objects
Decodes a byte array back to a Variant value. Decoding objects is allowed.
ceil
Rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x. Supported types: int, float, Vector2, Vector2i, Vector3, Vector3i, Vector4, Vector4i.
ceilf
Rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.
ceili
Rounds x upward (towards positive infinity), returning the smallest whole number that is not less than x.
clamp
Clamps the value, returning a Variant not less than min and not more than max. Any values that can be compared with the less than and greater than operators will work.
clampf
Clamps the value, returning a float not less than min and not more than max.
clampi
Clamps the value, returning an int not less than min and not more than max.
cos
Returns the cosine of angle angle_rad in radians.
cosh
Returns the hyperbolic cosine of x in radians.
cubic_interpolate
Cubic interpolates between two values by the factor defined in weight with pre and post values.
cubic_interpolate_angle
Cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also [method lerp_angle].
cubic_interpolate_angle_in_time
Cubic interpolates between two rotation values with shortest path by the factor defined in weight with pre and post values. See also [method lerp_angle].
cubic_interpolate_in_time
Cubic interpolates between two values by the factor defined in weight with pre and post values.
db_to_linear
Converts from decibels to linear energy (audio).
deg_to_rad
Converts an angle expressed in degrees to radians.
ease
Returns an “eased” value of x based on an easing function defined with curve. This easing function is based on an exponent. The curve can be any floating-point number, with specific values leading to the following behaviors:
error_string
Returns a human-readable name for the given [enum Error] code.
exp
The natural exponential function. It raises the mathematical constant e to the power of x and returns it.
floor
Rounds x downward (towards negative infinity), returning the largest whole number that is not more than x. Supported types: int, float, Vector2, Vector2i, Vector3, Vector3i, Vector4, Vector4i.
floorf
Rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.
floori
Rounds x downward (towards negative infinity), returning the largest whole number that is not more than x.
fmod
Returns the floating-point remainder of x divided by y, keeping the sign of x.
fposmod
Returns the floating-point modulus of x divided by y, wrapping equally in positive and negative.
hash
Returns the integer hash of the passed variable.
inverse_lerp
Returns an interpolation or extrapolation factor considering the range specified in from and to, and the interpolated value specified in weight. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive). If weight is located outside this range, then an extrapolation factor will be returned (return value lower than 0.0 or greater than 1.0). Use [method clamp] on the result of [method inverse_lerp] if this is not desired.
is_equal_approx
Returns true if a and b are approximately equal to each other.
is_finite
Returns whether x is a finite value, i.e. it is not @GDScript.NAN, positive infinity, or negative infinity. See also [method is_inf] and [method is_nan].
is_inf
Returns true if x is either positive infinity or negative infinity. See also [method is_finite] and [method is_nan].
is_nan
Returns true if x is a NaN (“Not a Number” or invalid) value. This method is needed as @GDScript.NAN is not equal to itself, which means x == NAN can’t be used to check whether a value is a NaN.
is_same
Returns true, for value types, if a and b share the same value. Returns true, for reference types, if the references of a and b are the same.
is_zero_approx
Returns true if x is zero or almost zero. The comparison is done using a tolerance calculation with a small internal epsilon.
lerp
Linearly interpolates between two values by the factor defined in weight. To perform interpolation, weight should be between 0.0 and 1.0 (inclusive). However, values outside this range are allowed and can be used to perform extrapolation. If this is not desired, use [method clampf] to limit weight.
lerp_angle
Linearly interpolates between two angles (in radians) by a weight value between 0.0 and 1.0.
lerpf
Linearly interpolates between two values by the factor defined in weight. To perform interpolation, weight should be between 0.0 and 1.0 (inclusive). However, values outside this range are allowed and can be used to perform extrapolation. If this is not desired, use [method clampf] on the result of this function.
linear_to_db
Converts from linear energy to decibels (audio). Since volume is not normally linear, this can be used to implement volume sliders that behave as expected.
log
Returns the natural logarithm of x (base e, with e being approximately 2.71828). This is the amount of time needed to reach a certain level of continuous growth.
max
Returns the maximum of the given numeric values. This function can take any number of arguments.
maxf
Returns the maximum of two float values.
maxi
Returns the maximum of two int values.
min
Returns the minimum of the given numeric values. This function can take any number of arguments.
minf
Returns the minimum of two float values.
mini
Returns the minimum of two int values.
move_toward
Moves from toward to by the delta amount. Will not go past to.
nearest_po2
Returns the smallest integer power of 2 that is greater than or equal to value.
pingpong
Wraps value between 0 and the length. If the limit is reached, the next value the function returns is decreased to the 0 side or increased to the length side (like a triangle wave). If length is less than zero, it becomes positive.
posmod
Returns the integer modulus of x divided by y that wraps equally in positive and negative.
pow
Returns the result of base raised to the power of exp.
print
Converts one or more arguments of any type to string in the best way possible and prints them to the console.
print_custom
Low-level printing of log messages with full control over level, source location and editor toast.
print_rich
Converts one or more arguments of any type to string in the best way possible and prints them to the console.
print_verbose
If verbose mode is enabled (is_stdout_verbose returning true), converts one or more arguments of any type to string in the best way possible and prints them to the console.
printerr
Prints one or more arguments to strings in the best way possible to standard error line.
printraw
Prints one or more arguments to strings in the best way possible to the OS terminal. Unlike [method print], no newline is automatically added at the end.
prints
Prints one or more arguments to the console with a space between each argument.
printt
Prints one or more arguments to the console with a tab between each argument.
push_error
Pushes an error message to Godot’s built-in debugger and to the OS terminal.
push_warning
Pushes a warning message to Godot’s built-in debugger and to the OS terminal.
rad_to_deg
Converts an angle expressed in radians to degrees.
rand_from_seed
Given a seed, returns a PackedInt64Array of size 2, where its first element is the randomized int value, and the second element is the same as seed. Passing the same seed consistently returns the same array.
randf
Returns a random floating-point value between 0.0 and 1.0 (inclusive).
randf_range
Returns a random floating-point value between from and to (inclusive).
randfn
Returns a normally-distributed, pseudo-random floating-point value from the specified mean and a standard deviation. This is also known as a Gaussian distribution.
randi
Returns a random unsigned 32-bit integer. Use remainder to obtain a random value in the interval [0, N - 1] (where N is smaller than 2^32).
randi_range
Returns a random signed 32-bit integer between from and to (inclusive). If to is lesser than from, they are swapped.
randomize
Randomizes the seed (or the internal state) of the random number generator. The current implementation uses a number based on the device’s time.
remap
Maps a value from range [istart, istop] to [ostart, ostop]. See also [method lerp] and [method inverse_lerp]. If value is outside [istart, istop], then the resulting value will also be outside [ostart, ostop]. If this is not desired, use [method clamp] on the result of this function.
rid_allocate_id
Allocates a unique ID which can be used by the implementation to construct an RID. This is used mainly from native extensions to implement servers.
rid_from_int64
Creates an RID from a base. This is used mainly from native extensions to build servers.
rotate_toward
Rotates from toward to by the delta amount. Will not go past to.
round
Rounds x to the nearest whole number, with halfway cases rounded away from 0. Supported types: int, float, Vector2, Vector2i, Vector3, Vector3i, Vector4, Vector4i.
roundf
Rounds x to the nearest whole number, with halfway cases rounded away from 0.
roundi
Rounds x to the nearest whole number, with halfway cases rounded away from 0.
seed
Sets the seed for the random number generator to base. Setting the seed manually can ensure consistent, repeatable results for most random functions.
sign
Returns the same type of Variant as x, with -1 for negative values, 1 for positive values, and 0 for zeros. For nan values it returns 0.
signf
Returns -1.0 if x is negative, 1.0 if x is positive, and 0.0 if x is zero. For nan values of x it returns 0.0.
signi
Returns -1 if x is negative, 1 if x is positive, and 0 if x is zero.
sin
Returns the sine of angle angle_rad in radians.
sinh
Returns the hyperbolic sine of x.
smoothstep
Returns a smooth cubic Hermite interpolation between 0 and 1.
snapped
Returns the multiple of step that is the closest to x. This can also be used to round a floating-point number to an arbitrary number of decimals.
snappedf
Returns the multiple of step that is the closest to x. This can also be used to round a floating-point number to an arbitrary number of decimals.
snappedi
Returns the multiple of step that is the closest to x.
sqrt
Returns the square root of x, where x is a non-negative number.
step_decimals
Returns the position of the first non-zero digit, after the decimal point. Note that the maximum return value is 10, which is a design decision in the implementation.
str
Converts one or more arguments of any Variant type to a String in the best way possible.
str_to_var
Converts a formatted string that was returned by [method var_to_str] to the original Variant.
tan
Returns the tangent of angle angle_rad in radians.
tanh
Returns the hyperbolic tangent of x.
type_convert
Converts the given variant to the given type, using the [enum Variant.Type] values. This method is generous with how it handles types, it can automatically convert between array types, convert numeric Strings to int, and converting most things to String.
type_string
Returns a human-readable name of the given type, using the [enum Variant.Type] values.
typeof_
Returns the internal type of the given variable, using the [enum Variant.Type] values.
var_to_bytes
Encodes a Variant value to a byte array, without encoding objects. Deserialization can be done with [method bytes_to_var].
var_to_bytes_with_objects
Encodes a Variant value to a byte array. Encoding objects is allowed (and can potentially include executable code). Deserialization can be done with [method bytes_to_var_with_objects].
var_to_str
Converts a Variant variable to a formatted String that can then be parsed using [method str_to_var].
weakref
Specific notes for this function
wrap
Wraps the Variant value between min and max. min is inclusive while max is exclusive. This can be used for creating loop-like behavior or infinite surfaces.
wrapf
Wraps the float value between min and max. min is inclusive while max is exclusive. This can be used for creating loop-like behavior or infinite surfaces.
wrapi
Wraps the integer value between min and max. min is inclusive while max is exclusive. This can be used for creating loop-like behavior or infinite surfaces.