Skip to content

Global functions and helpers

GD

Package: godot.global. Methods are exposed as static JVM methods. Numeric operations run through the binding/JVM implementation; engine-backed operations require a running Godot runtime.

1
2
3
import godot.global.GD

GD.print("Ready")
1
2
3
import godot.global.GD;

GD.print("Ready");
1
2
3
import godot.global.GD

GD.print("Ready")

Resource loading

load loads a resource at call time. path is required; use an absolute resource path such as res://player.tscn. typeHint defaults to ""; cacheMode defaults to ResourceLoader.CacheMode.REUSE. Returns the resource or null on failure. Java overloads allow omitting the optional arguments.

1
2
3
4
import godot.api.PackedScene
import godot.global.GD

val scene: PackedScene? = GD.load<PackedScene>("res://player.tscn")
1
2
3
4
import godot.api.PackedScene;
import godot.global.GD;

PackedScene scene = GD.load("res://player.tscn");
1
2
3
4
import godot.api.PackedScene
import godot.global.GD

val scene: PackedScene = GD.load[PackedScene]("res://player.tscn")

There is no compile-time preload equivalent. A generic result type does not turn an incompatible resource into that type.

Logging

An exception escaping a JVM callback is logged with its stack trace. The Godot-side call returns a default value (nil for a registered function result) and the game keeps running; the remaining statements in the failed callback do not run.

These operations return no value. Except printStack(), each accepts zero or more Variant/JVM values to format.

Method Output
print(args...) Godot output
printRich(args...) Rich-text Godot output
printVerbose(args...) Verbose output
printErr(args...) Error output
printRaw(args...) Raw output
prints(args...) Values separated by spaces
printt(args...) Values separated by tabs
pushError(args...) Godot error report
pushWarning(args...) Godot warning report
printStack() Current JVM thread's stack trace

Objects and shutdown

Method Result/effect
isInstanceValid(object) Boolean; false for null or a deleted native object
syncMemory() Requests binding memory synchronization; main thread only, other threads get an error and no sync
callWhenClosing(callback) Registers a no-argument, Kotlin-Unit-returning shutdown callback

See Objects and lifetime for language syntax and lifetime restrictions.

Strings, colors, and assertions

Method Contract
len(value) Integer length for supported strings/collections/core containers; unsupported values throw IllegalArgumentException
ord(text) Integer value of the first UTF-16 character; an empty string fails with an index error
char(code) Converts a JVM character code to a one-character string
Color8(r8, g8, b8, a8) Builds a Color by dividing integer channels by 255; Kotlin alpha default is 255
ColorN(name, alpha) Named color with alpha; Kotlin alpha default is 1f
assert(condition, message) JVM assertion; message defaults to empty and assertions must be enabled to take effect

Java cannot call methods named char or assert in source because these are Java keywords. Use Java character conversion or Java assertions. Java/Scala calls to Color8 and ColorN supply all arguments.

1
2
val text = GD.char(65)
GD.assert(text == "A", "Unexpected character")
1
2
String text = Character.toString((char) 65);
assert text.equals("A") : "Unexpected character";
1
2
val text = GD.char(65)
GD.assert(text == "A", "Unexpected character")

Random numbers

Method Result/effect
randf() Random floating-point value from Godot's generator
randfRange(from, to) Floating-point range sample; bounds are single precision
randfn(mean, deviation) Gaussian sample; Kotlin defaults are 0f, 1f; Java/Scala supply both
randi() Random integer from Godot's generator
randiRange(from, to) Integer range sample; input bounds are 32-bit integers
randFromSeed(seed) kotlin.Pair<Long, Long> containing the generated integer and the generator's seed after the draw
randomize() Reseeds the shared generator
seed(seed) Sets its 64-bit seed
1
2
3
GD.seed(42L)
val roll = GD.randiRange(1, 6)
val seeded: Pair<Long, Long> = GD.randFromSeed(42L)
1
2
3
GD.seed(42L);
long roll = GD.randiRange(1, 6);
kotlin.Pair<Long, Long> seeded = GD.randFromSeed(42L);
1
2
3
GD.seed(42L)
val roll = GD.randiRange(1, 6)
val seeded: kotlin.Pair[java.lang.Long, java.lang.Long] = GD.randFromSeed(42L)

Numeric functions

The following tables list the available overloads, including return types. Angles are in radians unless a conversion function says otherwise. Overload names preserve the binding's exact spelling. These are call signatures, not declarations to paste into a script.

Function Overloads
abs abs(s: Int): Int
abs(s: Long): Long
abs(s: Float): Float
abs(s: Double): Double
acos acos(s: Float): Float
acos(s: Double): Double
acosh acosh(x: Float): Float
acosh(x: Double): Double
angleDifference angleDifference(from: Float, to: Float): Float
angleDifference(from: Double, to: Double): Double
asin asin(s: Float): Float
asin(s: Double): Double
asinh asinh(x: Float): Float
asinh(x: Double): Double
atan atan(s: Float): Float
atan(s: Double): Double
atan2 atan2(y: Float, x: Float): Float
atan2(y: Double, x: Double): Double
atanh atanh(x: Float): Float
atanh(x: Double): Double
bezierDerivative bezierDerivative(start: Float, control1: Float, control2: Float, end: Float, t: Float): Float
bezierDerivative(start: Double, control1: Double, control2: Double, end: Double, t: Double): Double
cartesian2polar cartesian2polar(x: Float, y: Float): Vector2
cartesian2polar(x: Double, y: Double): Vector2
ceil ceil(s: Float): Float
ceil(s: Double): Double
clamp clamp(value: Float, min: Float, max: Float): Float
clamp(value: Double, min: Double, max: Double): Double
clamp(value: Float, min: Int, max: Int): Float
clamp(value: Double, min: Long, max: Long): Double
cos cos(s: Float): Float
cos(s: Double): Double
cosh cosh(s: Float): Float
cosh(s: Double): Double
dbToLinear dbToLinear(db: Float): Double
dbToLinear(db: Double): Double
degToRad degToRad(s: Float): Double
degToRad(s: Double): Double
ease ease(value: Float, curve: Float): Float
ease(value: Double, curve: Double): Double
exp exp(s: Float): Float
exp(s: Double): Double
floor floor(s: Float): Float
floor(s: Double): Double
floori floori(s: Float): Int
floori(s: Double): Int
fmod fmod(a: Float, b: Float): Float
fmod(a: Double, b: Double): Double
fposmod fposmod(arg0: Float, arg1: Float): Float
fposmod(arg0: Double, arg1: Double): Double
inverseLerp inverseLerp(from: Float, to: Float, weight: Float): Float
inverseLerp(from: Double, to: Double, weight: Double): Double
isEqualApprox isEqualApprox(a: Float, b: Float): Boolean
isEqualApprox(a: Double, b: Double): Boolean
isFinite isFinite(s: Float): Boolean
isFinite(s: Double): Boolean
isInf isInf(s: Float): Boolean
isInf(s: Double): Boolean
isNan isNan(s: Float): Boolean
isNan(s: Double): Boolean
isSame isSame(a: Any, b: Any): Boolean
isZeroApprox isZeroApprox(s: Float): Boolean
isZeroApprox(s: Double): Boolean
lerp lerp(from: Int, to: Int, weight: Float): Float
lerp(from: Long, to: Long, weight: Double): Double
lerp(from: Float, to: Float, weight: Float): Float
lerp(from: Double, to: Double, weight: Double): Double
lerp(from: Color, to: Color, weight: Float): Color
lerp(from: Color, to: Color, weight: Double): Color
lerp(from: Vector2, to: Vector2, weight: Float): Vector2
lerp(from: Vector2, to: Vector2, weight: Double): Vector2
lerp(from: Vector3, to: Vector3, weight: Float): Vector3
lerp(from: Vector3, to: Vector3, weight: Double): Vector3
lerpAngle lerpAngle(arg0: Float, arg1: Float, arg2: Float): Float
lerpAngle(arg0: Double, arg1: Double, arg2: Double): Double
linearToDb linearToDb(nrg: Float): Double
linearToDb(nrg: Double): Double
log log(s: Float): Float
log(s: Double): Double
max max(a: Int, b: Int): Int
max(a: Long, b: Long): Long
max(a: Float, b: Float): Float
max(a: Double, b: Double): Double
min min(a: Int, b: Int): Int
min(a: Long, b: Long): Long
min(a: Float, b: Float): Float
min(a: Double, b: Double): Double
mod mod(a: Int, b: Int): Int
mod(a: Long, b: Long): Long
moveToward moveToward(from: Int, to: Int, delta: Int): Int
moveToward(from: Long, to: Long, delta: Long): Long
moveToward(from: Float, to: Float, delta: Float): Float
moveToward(from: Double, to: Double, delta: Double): Double
nearestPo2 nearestPo2(arg0: Int): Int
nearestPo2(arg0: Long): Long
nearestPo2(arg0: Float): Float
nearestPo2(arg0: Double): Double
polarToCartesian polarToCartesian(r: Float, th: Float): Vector2
polarToCartesian(r: Double, th: Double): Vector2
posmod posmod(arg0: Int, arg1: Int): Int
posmod(arg0: Long, arg1: Long): Long
pow pow(base: Float, exp: Float): Float
pow(base: Double, exp: Double): Double
radToDeg radToDeg(rad: Float): Float
radToDeg(rad: Double): Double
remap remap(value: Float, istart: Float, istop: Float, ostart: Float, ostop: Float): Float
remap(value: Double, istart: Double, istop: Double, ostart: Double, ostop: Double): Double
rotateToward rotateToward(from: Float, to: Float, delta: Float): Float
rotateToward(from: Double, to: Double, delta: Double): Double
round round(s: Float): Float
round(s: Double): Double
sign sign(s: Float): Float
sign(s: Double): Double
sin sin(s: Float): Float
sin(s: Double): Double
sinh sinh(s: Float): Float
sinh(s: Double): Double
smoothstep smoothstep(from: Float, to: Float, weight: Float): Float
smoothstep(from: Double, to: Double, weight: Double): Double
snapped snapped(x: Int, step: Int): Int
snapped(x: Long, step: Long): Long
snapped(x: Float, step: Float): Float
snapped(x: Double, step: Double): Double
snappedf snappedf(x: Float, step: Float): Float
snappedf(x: Double, step: Double): Double
snappedi snappedi(x: Float, step: Int): Int
snappedi(x: Double, step: Long): Long
sqrt sqrt(s: Float): Float
sqrt(s: Double): Double
stepDecimals stepDecimals(step: Float): Int
stepDecimals(step: Double): Int
tan tan(s: Float): Float
tan(s: Double): Double
tanh tanh(s: Float): Float
tanh(s: Double): Double
wrapf wrapf(value: Float, min: Float, max: Float): Float
wrapf(value: Double, min: Double, max: Double): Double
wrapi wrapi(value: Int, min: Int, max: Int): Int
wrapi(value: Long, min: Long, max: Long): Long
Function Overloads
abs int abs(int s)
long abs(long s)
float abs(float s)
double abs(double s)
acos float acos(float s)
double acos(double s)
acosh float acosh(float x)
double acosh(double x)
angleDifference float angleDifference(float from, float to)
double angleDifference(double from, double to)
asin float asin(float s)
double asin(double s)
asinh float asinh(float x)
double asinh(double x)
atan float atan(float s)
double atan(double s)
atan2 float atan2(float y, float x)
double atan2(double y, double x)
atanh float atanh(float x)
double atanh(double x)
bezierDerivative float bezierDerivative(float start, float control1, float control2, float end, float t)
double bezierDerivative(double start, double control1, double control2, double end, double t)
cartesian2polar Vector2 cartesian2polar(float x, float y)
Vector2 cartesian2polar(double x, double y)
ceil float ceil(float s)
double ceil(double s)
clamp float clamp(float value, float min, float max)
double clamp(double value, double min, double max)
float clamp(float value, int min, int max)
double clamp(double value, long min, long max)
cos float cos(float s)
double cos(double s)
cosh float cosh(float s)
double cosh(double s)
dbToLinear double dbToLinear(float db)
double dbToLinear(double db)
degToRad double degToRad(float s)
double degToRad(double s)
ease float ease(float value, float curve)
double ease(double value, double curve)
exp float exp(float s)
double exp(double s)
floor float floor(float s)
double floor(double s)
floori int floori(float s)
int floori(double s)
fmod float fmod(float a, float b)
double fmod(double a, double b)
fposmod float fposmod(float arg0, float arg1)
double fposmod(double arg0, double arg1)
inverseLerp float inverseLerp(float from, float to, float weight)
double inverseLerp(double from, double to, double weight)
isEqualApprox boolean isEqualApprox(float a, float b)
boolean isEqualApprox(double a, double b)
isFinite boolean isFinite(float s)
boolean isFinite(double s)
isInf boolean isInf(float s)
boolean isInf(double s)
isNan boolean isNan(float s)
boolean isNan(double s)
isSame boolean isSame(java.lang.Object a, java.lang.Object b)
isZeroApprox boolean isZeroApprox(float s)
boolean isZeroApprox(double s)
lerp float lerp(int from, int to, float weight)
double lerp(long from, long to, double weight)
float lerp(float from, float to, float weight)
double lerp(double from, double to, double weight)
Color lerp(Color from, Color to, float weight)
Color lerp(Color from, Color to, double weight)
Vector2 lerp(Vector2 from, Vector2 to, float weight)
Vector2 lerp(Vector2 from, Vector2 to, double weight)
Vector3 lerp(Vector3 from, Vector3 to, float weight)
Vector3 lerp(Vector3 from, Vector3 to, double weight)
lerpAngle float lerpAngle(float arg0, float arg1, float arg2)
double lerpAngle(double arg0, double arg1, double arg2)
linearToDb double linearToDb(float nrg)
double linearToDb(double nrg)
log float log(float s)
double log(double s)
max int max(int a, int b)
long max(long a, long b)
float max(float a, float b)
double max(double a, double b)
min int min(int a, int b)
long min(long a, long b)
float min(float a, float b)
double min(double a, double b)
mod int mod(int a, int b)
long mod(long a, long b)
moveToward int moveToward(int from, int to, int delta)
long moveToward(long from, long to, long delta)
float moveToward(float from, float to, float delta)
double moveToward(double from, double to, double delta)
nearestPo2 int nearestPo2(int arg0)
long nearestPo2(long arg0)
float nearestPo2(float arg0)
double nearestPo2(double arg0)
polarToCartesian Vector2 polarToCartesian(float r, float th)
Vector2 polarToCartesian(double r, double th)
posmod int posmod(int arg0, int arg1)
long posmod(long arg0, long arg1)
pow float pow(float base, float exp)
double pow(double base, double exp)
radToDeg float radToDeg(float rad)
double radToDeg(double rad)
remap float remap(float value, float istart, float istop, float ostart, float ostop)
double remap(double value, double istart, double istop, double ostart, double ostop)
rotateToward float rotateToward(float from, float to, float delta)
double rotateToward(double from, double to, double delta)
round float round(float s)
double round(double s)
sign float sign(float s)
double sign(double s)
sin float sin(float s)
double sin(double s)
sinh float sinh(float s)
double sinh(double s)
smoothstep float smoothstep(float from, float to, float weight)
double smoothstep(double from, double to, double weight)
snapped int snapped(int x, int step)
long snapped(long x, long step)
float snapped(float x, float step)
double snapped(double x, double step)
snappedf float snappedf(float x, float step)
double snappedf(double x, double step)
snappedi int snappedi(float x, int step)
long snappedi(double x, long step)
sqrt float sqrt(float s)
double sqrt(double s)
stepDecimals int stepDecimals(float step)
int stepDecimals(double step)
tan float tan(float s)
double tan(double s)
tanh float tanh(float s)
double tanh(double s)
wrapf float wrapf(float value, float min, float max)
double wrapf(double value, double min, double max)
wrapi int wrapi(int value, int min, int max)
long wrapi(long value, long min, long max)
Function Overloads
abs abs(s: Int): Int
abs(s: Long): Long
abs(s: Float): Float
abs(s: Double): Double
acos acos(s: Float): Float
acos(s: Double): Double
acosh acosh(x: Float): Float
acosh(x: Double): Double
angleDifference angleDifference(from: Float, to: Float): Float
angleDifference(from: Double, to: Double): Double
asin asin(s: Float): Float
asin(s: Double): Double
asinh asinh(x: Float): Float
asinh(x: Double): Double
atan atan(s: Float): Float
atan(s: Double): Double
atan2 atan2(y: Float, x: Float): Float
atan2(y: Double, x: Double): Double
atanh atanh(x: Float): Float
atanh(x: Double): Double
bezierDerivative bezierDerivative(start: Float, control1: Float, control2: Float, end: Float, t: Float): Float
bezierDerivative(start: Double, control1: Double, control2: Double, end: Double, t: Double): Double
cartesian2polar cartesian2polar(x: Float, y: Float): Vector2
cartesian2polar(x: Double, y: Double): Vector2
ceil ceil(s: Float): Float
ceil(s: Double): Double
clamp clamp(value: Float, min: Float, max: Float): Float
clamp(value: Double, min: Double, max: Double): Double
clamp(value: Float, min: Int, max: Int): Float
clamp(value: Double, min: Long, max: Long): Double
cos cos(s: Float): Float
cos(s: Double): Double
cosh cosh(s: Float): Float
cosh(s: Double): Double
dbToLinear dbToLinear(db: Float): Double
dbToLinear(db: Double): Double
degToRad degToRad(s: Float): Double
degToRad(s: Double): Double
ease ease(value: Float, curve: Float): Float
ease(value: Double, curve: Double): Double
exp exp(s: Float): Float
exp(s: Double): Double
floor floor(s: Float): Float
floor(s: Double): Double
floori floori(s: Float): Int
floori(s: Double): Int
fmod fmod(a: Float, b: Float): Float
fmod(a: Double, b: Double): Double
fposmod fposmod(arg0: Float, arg1: Float): Float
fposmod(arg0: Double, arg1: Double): Double
inverseLerp inverseLerp(from: Float, to: Float, weight: Float): Float
inverseLerp(from: Double, to: Double, weight: Double): Double
isEqualApprox isEqualApprox(a: Float, b: Float): Boolean
isEqualApprox(a: Double, b: Double): Boolean
isFinite isFinite(s: Float): Boolean
isFinite(s: Double): Boolean
isInf isInf(s: Float): Boolean
isInf(s: Double): Boolean
isNan isNan(s: Float): Boolean
isNan(s: Double): Boolean
isSame isSame(a: Any, b: Any): Boolean
isZeroApprox isZeroApprox(s: Float): Boolean
isZeroApprox(s: Double): Boolean
lerp lerp(from: Int, to: Int, weight: Float): Float
lerp(from: Long, to: Long, weight: Double): Double
lerp(from: Float, to: Float, weight: Float): Float
lerp(from: Double, to: Double, weight: Double): Double
lerp(from: Color, to: Color, weight: Float): Color
lerp(from: Color, to: Color, weight: Double): Color
lerp(from: Vector2, to: Vector2, weight: Float): Vector2
lerp(from: Vector2, to: Vector2, weight: Double): Vector2
lerp(from: Vector3, to: Vector3, weight: Float): Vector3
lerp(from: Vector3, to: Vector3, weight: Double): Vector3
lerpAngle lerpAngle(arg0: Float, arg1: Float, arg2: Float): Float
lerpAngle(arg0: Double, arg1: Double, arg2: Double): Double
linearToDb linearToDb(nrg: Float): Double
linearToDb(nrg: Double): Double
log log(s: Float): Float
log(s: Double): Double
max max(a: Int, b: Int): Int
max(a: Long, b: Long): Long
max(a: Float, b: Float): Float
max(a: Double, b: Double): Double
min min(a: Int, b: Int): Int
min(a: Long, b: Long): Long
min(a: Float, b: Float): Float
min(a: Double, b: Double): Double
mod mod(a: Int, b: Int): Int
mod(a: Long, b: Long): Long
moveToward moveToward(from: Int, to: Int, delta: Int): Int
moveToward(from: Long, to: Long, delta: Long): Long
moveToward(from: Float, to: Float, delta: Float): Float
moveToward(from: Double, to: Double, delta: Double): Double
nearestPo2 nearestPo2(arg0: Int): Int
nearestPo2(arg0: Long): Long
nearestPo2(arg0: Float): Float
nearestPo2(arg0: Double): Double
polarToCartesian polarToCartesian(r: Float, th: Float): Vector2
polarToCartesian(r: Double, th: Double): Vector2
posmod posmod(arg0: Int, arg1: Int): Int
posmod(arg0: Long, arg1: Long): Long
pow pow(base: Float, exp: Float): Float
pow(base: Double, exp: Double): Double
radToDeg radToDeg(rad: Float): Float
radToDeg(rad: Double): Double
remap remap(value: Float, istart: Float, istop: Float, ostart: Float, ostop: Float): Float
remap(value: Double, istart: Double, istop: Double, ostart: Double, ostop: Double): Double
rotateToward rotateToward(from: Float, to: Float, delta: Float): Float
rotateToward(from: Double, to: Double, delta: Double): Double
round round(s: Float): Float
round(s: Double): Double
sign sign(s: Float): Float
sign(s: Double): Double
sin sin(s: Float): Float
sin(s: Double): Double
sinh sinh(s: Float): Float
sinh(s: Double): Double
smoothstep smoothstep(from: Float, to: Float, weight: Float): Float
smoothstep(from: Double, to: Double, weight: Double): Double
snapped snapped(x: Int, step: Int): Int
snapped(x: Long, step: Long): Long
snapped(x: Float, step: Float): Float
snapped(x: Double, step: Double): Double
snappedf snappedf(x: Float, step: Float): Float
snappedf(x: Double, step: Double): Double
snappedi snappedi(x: Float, step: Int): Int
snappedi(x: Double, step: Long): Long
sqrt sqrt(s: Float): Float
sqrt(s: Double): Double
stepDecimals stepDecimals(step: Float): Int
stepDecimals(step: Double): Int
tan tan(s: Float): Float
tan(s: Double): Double
tanh tanh(s: Float): Float
tanh(s: Double): Double
wrapf wrapf(value: Float, min: Float, max: Float): Float
wrapf(value: Double, min: Double, max: Double): Double
wrapi wrapi(value: Int, min: Int, max: Int): Int
wrapi(value: Long, min: Long, max: Long): Long

Numeric behavior

Family Behavior
abs, min, max, clamp, sign Absolute value, extrema, range clamp, sign
acos, asin, atan, atan2, sin, cos, tan Trigonometric functions
asinh, acosh, atanh, sinh, cosh, tanh Hyperbolic functions
ceil, floor, floori, round Rounding; round rounds halfway cases away from zero and floori returns a 32-bit integer
exp, log, pow, sqrt Exponential, natural logarithm, power, square root
degToRad, radToDeg Degree/radian conversion
angleDifference, lerpAngle, rotateToward Wrapped angular difference/interpolation/movement
lerp, inverseLerp, remap Linear interpolation, inverse weight, interval mapping
moveToward Moves toward the target without overshooting
ease, smoothstep, bezierDerivative Easing, smooth interpolation, cubic Bezier derivative
mod, fmod JVM remainder
posmod, fposmod Sign-adjusted modulus
snapped, snappedf, snappedi, stepDecimals Step snapping and decimal precision helpers
wrapi, wrapf Wrap into [min, max); same formulas as the engine's Math::wrapi and Math::wrapf
cartesian2polar, polarToCartesian Coordinate conversion; the latter returns (r * cos(angle), r * sin(angle))
nearestPo2 Nearest upper power-of-two helper
dbToLinear, linearToDb Decibel/linear conversion
isEqualApprox, isZeroApprox Binding approximate comparisons
isFinite, isInf, isNan Floating-point classification
isSame JVM equality (== in the Kotlin implementation), not a native pointer comparison

Other binding helpers

API Reference
String-name and node-path conversions; collection mutation Types and conversions
asStatic / ObjectUtils.asStatic Objects and lifetime
connectMethod, connectLambda, SignalConnectors Signals
methodCallableN, lambdaCallableN, asCallable Callables
godotCoroutine, await and dispatchers Coroutines