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 function | godot-rust APIs |
|---|---|
instance_from_id | Gd::from_instance_id()Gd::try_from_instance_id() |
is_instance_valid | Gd::is_instance_valid() |
is_instance_id_valid | InstanceId::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:
- Color:
ColorChannelOrder - Projection:
ProjectionEye,ProjectionPlane - Rectangle:
Side,Corner(godot-generated) - Rotation:
EulerOrder(godot-generated) - Variant:
VariantType,VariantOperator - Vector:
Vector2Axis,Vector3Axis,Vector4Axis
Some enums are closely related to property/method registration and are located in godot::register::info:
PropertyHint(godot-generated)PropertyUsageFlags(godot-generated)MethodFlags(godot-generated)
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
- Horizontal
Alignment - Inline
Alignment - JoyAxis
- JoyButton
- Key
- KeyLocation
- KeyModifier
Mask - Midi
Message - Godot enum name:
MIDIMessage. - Mouse
Button - Mouse
Button Mask - Print
Record - Log record passed to
print_custom(). - Print
Source - Source location associated with a
PrintRecord. - Vertical
Alignment
Enums§
- Clock
Direction - 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.
- Print
Level - Severity level for
print_custom().
Functions§
- abs
- Returns the absolute value of a
Variantparameterx(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
xin radians. Use to get the angle of cosinex.xwill be clamped between-1.0and1.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 ifxis larger or equal to 1. For values ofxlower 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]. Whenfromandtoare opposite, returns-PIiffromis smaller thanto, orPIotherwise. - asin
- Returns the arc sine of
xin radians. Use to get the angle of sinex.xwill be clamped between-1.0and1.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
xin radians. Use it to get the angle from an angle’s tangent in trigonometry. - atan2
- Returns the arc tangent of
y/xin radians. Use to get the angle of tangenty/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 ifxis between -1 and 1 (non-inclusive). - bezier_
derivative - Returns the derivative at the given
ton a one-dimensional Bézier curve defined by the givencontrol_1,control_2, andendpoints. - bezier_
interpolate - Returns the point at the given
ton a one-dimensional Bézier curve defined by the givencontrol_1,control_2, andendpoints. - bytes_
to_ var - Decodes a byte array back to a
Variantvalue, without decoding objects. - bytes_
to_ var_ with_ objects - Decodes a byte array back to a
Variantvalue. Decoding objects is allowed. - ceil
- Rounds
xupward (towards positive infinity), returning the smallest whole number that is not less thanx. Supported types:int,float,Vector2,Vector2i,Vector3,Vector3i,Vector4,Vector4i. - ceilf
- Rounds
xupward (towards positive infinity), returning the smallest whole number that is not less thanx. - ceili
- Rounds
xupward (towards positive infinity), returning the smallest whole number that is not less thanx. - clamp
- Clamps the
value, returning aVariantnot less thanminand not more thanmax. Any values that can be compared with the less than and greater than operators will work. - clampf
- Clamps the
value, returning afloatnot less thanminand not more thanmax. - clampi
- Clamps the
value, returning anintnot less thanminand not more thanmax. - cos
- Returns the cosine of angle
angle_radin radians. - cosh
- Returns the hyperbolic cosine of
xin radians. - cubic_
interpolate - Cubic interpolates between two values by the factor defined in
weightwithpreandpostvalues. - cubic_
interpolate_ angle - Cubic interpolates between two rotation values with shortest path by the factor defined in
weightwithpreandpostvalues. See also [method lerp_angle]. - cubic_
interpolate_ angle_ in_ time - Cubic interpolates between two rotation values with shortest path by the factor defined in
weightwithpreandpostvalues. See also [method lerp_angle]. - cubic_
interpolate_ in_ time - Cubic interpolates between two values by the factor defined in
weightwithpreandpostvalues. - 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
xbased on an easing function defined withcurve. This easing function is based on an exponent. Thecurvecan 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
xand returns it. - floor
- Rounds
xdownward (towards negative infinity), returning the largest whole number that is not more thanx. Supported types:int,float,Vector2,Vector2i,Vector3,Vector3i,Vector4,Vector4i. - floorf
- Rounds
xdownward (towards negative infinity), returning the largest whole number that is not more thanx. - floori
- Rounds
xdownward (towards negative infinity), returning the largest whole number that is not more thanx. - fmod
- Returns the floating-point remainder of
xdivided byy, keeping the sign ofx. - fposmod
- Returns the floating-point modulus of
xdivided byy, 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
fromandto, and the interpolated value specified inweight. The returned value will be between0.0and1.0ifweightis betweenfromandto(inclusive). Ifweightis located outside this range, then an extrapolation factor will be returned (return value lower than0.0or greater than1.0). Use [method clamp] on the result of [method inverse_lerp] if this is not desired. - is_
equal_ approx - Returns
trueifaandbare approximately equal to each other. - is_
finite - Returns whether
xis 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
trueifxis either positive infinity or negative infinity. See also [method is_finite] and [method is_nan]. - is_nan
- Returns
trueifxis a NaN (“Not a Number” or invalid) value. This method is needed as@GDScript.NANis not equal to itself, which meansx == NANcan’t be used to check whether a value is a NaN. - is_same
- Returns
true, for value types, ifaandbshare the same value. Returnstrue, for reference types, if the references ofaandbare the same. - is_
zero_ approx - Returns
trueifxis 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,weightshould be between0.0and1.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 limitweight. - lerp_
angle - Linearly interpolates between two angles (in radians) by a
weightvalue between 0.0 and 1.0. - lerpf
- Linearly interpolates between two values by the factor defined in
weight. To perform interpolation,weightshould be between0.0and1.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
floatvalues. - maxi
- Returns the maximum of two
intvalues. - min
- Returns the minimum of the given numeric values. This function can take any number of arguments.
- minf
- Returns the minimum of two
floatvalues. - mini
- Returns the minimum of two
intvalues. - move_
toward - Moves
fromtowardtoby thedeltaamount. Will not go pastto. - nearest_
po2 - Returns the smallest integer power of 2 that is greater than or equal to
value. - pingpong
- Wraps
valuebetween0and thelength. If the limit is reached, the next value the function returns is decreased to the0side or increased to thelengthside (like a triangle wave). Iflengthis less than zero, it becomes positive. - posmod
- Returns the integer modulus of
xdivided byythat wraps equally in positive and negative. - pow
- Returns the result of
baseraised to the power ofexp. - 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_verbosereturningtrue), 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 aPackedInt64Arrayof size2, where its first element is the randomizedintvalue, and the second element is the same asseed. Passing the sameseedconsistently returns the same array. - randf
- Returns a random floating-point value between
0.0and1.0(inclusive). - randf_
range - Returns a random floating-point value between
fromandto(inclusive). - randfn
- Returns a normally-distributed, pseudo-random floating-point value from the specified
meanand a standarddeviation. 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
fromandto(inclusive). Iftois lesser thanfrom, 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
valuefrom range[istart, istop]to[ostart, ostop]. See also [method lerp] and [method inverse_lerp]. Ifvalueis 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
fromtowardtoby thedeltaamount. Will not go pastto. - round
- Rounds
xto the nearest whole number, with halfway cases rounded away from 0. Supported types:int,float,Vector2,Vector2i,Vector3,Vector3i,Vector4,Vector4i. - roundf
- Rounds
xto the nearest whole number, with halfway cases rounded away from 0. - roundi
- Rounds
xto 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
Variantasx, with-1for negative values,1for positive values, and0for zeros. Fornanvalues it returns 0. - signf
- Returns
-1.0ifxis negative,1.0ifxis positive, and0.0ifxis zero. Fornanvalues ofxit returns 0.0. - signi
- Returns
-1ifxis negative,1ifxis positive, and0ifxis zero. - sin
- Returns the sine of angle
angle_radin radians. - sinh
- Returns the hyperbolic sine of
x. - smoothstep
- Returns a smooth cubic Hermite interpolation between
0and1. - snapped
- Returns the multiple of
stepthat is the closest tox. This can also be used to round a floating-point number to an arbitrary number of decimals. - snappedf
- Returns the multiple of
stepthat is the closest tox. This can also be used to round a floating-point number to an arbitrary number of decimals. - snappedi
- Returns the multiple of
stepthat is the closest tox. - sqrt
- Returns the square root of
x, wherexis 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
Varianttype to aStringin the best way possible. - str_
to_ var - Converts a formatted
stringthat was returned by [method var_to_str] to the originalVariant. - tan
- Returns the tangent of angle
angle_radin radians. - tanh
- Returns the hyperbolic tangent of
x. - type_
convert - Converts the given
variantto the giventype, using the [enum Variant.Type] values. This method is generous with how it handles types, it can automatically convert between array types, convert numericStrings toint, and converting most things toString. - 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
Variantvalue to a byte array, without encoding objects. Deserialization can be done with [method bytes_to_var]. - var_
to_ bytes_ with_ objects - Encodes a
Variantvalue 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
Variantvariableto a formattedStringthat can then be parsed using [method str_to_var]. - weakref
- Specific notes for this function
- wrap
- Wraps the
Variantvaluebetweenminandmax.minis inclusive whilemaxis exclusive. This can be used for creating loop-like behavior or infinite surfaces. - wrapf
- Wraps the float
valuebetweenminandmax.minis inclusive whilemaxis exclusive. This can be used for creating loop-like behavior or infinite surfaces. - wrapi
- Wraps the integer
valuebetweenminandmax.minis inclusive whilemaxis exclusive. This can be used for creating loop-like behavior or infinite surfaces.