Godot's global functions.
Static variables
Static methods
staticbytes2Var(bytes:Array<UInt8>, ?allowObjects:Bool):Dynamic
Decodes a byte array back to a Variant
value.
If allowObjects
is true
decoding objects is allowed.
WARNING: Deserialized object can contain code which gets executed.
Do not set allowObjects
to true
if the serialized object comes from untrusted sources to avoid
potential security threats (remote code execution).
Parameters:
bytes | Byte array that will be decoded to a |
---|---|
allowObjects | If objects should be decoded. |
Returns:
The decoded Variant
.
staticconvert(what:Dynamic, type:Variant_Type):Dynamic
Converts from a Variant
type to another in the best way possible.
The type
parameter uses the godot.Variant_Type
values.
var a = new Vector2(1, 0);
// Prints 1
GD.Print(a.Length());
var b = GD.Convert(a, Variant.Type.String)
// Prints 6 as "(1, 0)" is 6 characters
GD.Print(b.Length);
Returns:
The Variant
converted to the given type
.
staticdb2Linear(db:Single):Single
Converts from decibels to linear energy (audio).
Parameters:
db | Decibels to convert. |
---|
Returns:
Audio volume as linear energy.
See also:
staticdecTime(value:Single, amount:Single, step:Single):Single
Returns the result of value
decreased by
step
* amount
.
// a = 59;
// float a = GD.DecTime(60, 10, 0.1f);
Parameters:
value | Value that will be decreased. |
---|---|
amount | Amount that will be decreased from |
step | Times the |
Returns:
The decreased value.
staticfuncRef(instance:Object, funcname:String):FuncRef
Get the godot.GD.funcRef
that refers to the function
with the given name funcname
in the
given object instance
.
Parameters:
instance | The object that contains the function. |
---|---|
funcname | The name of the function. |
Returns:
A reference to the given object's function.
statichash(var_:Dynamic):Int
Returns the integer hash of the variable passed.
GD.Print(GD.Hash("a")); // Prints 177670
Parameters:
var | Variable that will be hashed. |
---|
Returns:
Hash of the variable passed.
staticinstanceFromId(instanceId:UInt64):Object
Returns the godot.Object
that corresponds to instanceId
.
All Objects have a unique instance ID.
public class MyNode : Node
{
public string foo = "bar";
public override void _Ready()
{
ulong id = GetInstanceId();
var inst = (MyNode)GD.InstanceFromId(Id);
GD.Print(inst.foo); // Prints bar
}
}
Parameters:
instanceId | Instance ID of the Object to retrieve. |
---|
Returns:
The godot.Object
instance.
staticlinear2Db(linear:Single):Single
Converts from linear energy to decibels (audio). This can be used to implement volume sliders that behave as expected (since volume isn't linear).
Parameters:
linear | The linear energy to convert. |
---|
Returns:
Audio as decibels.
See also:
// "slider" refers to a node that inherits Range such as HSlider or VSlider. // Its range must be configured to go from 0 to 1. // Change the bus name if you'd like to change the volume of a specific bus only. AudioServer.SetBusVolumeDb(AudioServer.GetBusIndex("Master"), GD.Linear2Db(slider.value));
staticload<M0>(path:String):M0
Loads a resource from the filesystem located at path
.
The resource is loaded on the method call (unless it's referenced already
elsewhere, e.g. in another script or in the scene), which might cause slight delay,
especially when loading scenes. To avoid unnecessary delays when loading something
multiple times, either store the resource in a variable.
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 script.
Important: The path must be absolute, a local path will just return null
.
This method is a simplified version of godot.ResourceLoader.load
, which can be used
for more advanced scenarios.
// Load a scene called main located in the root of the project directory and cache it in a variable.
var main = GD.Load("res://main.tscn"); // main will contain a PackedScene resource.
Parameters:
path | Path of the |
---|
Returns:
The loaded godot.Resource
.
staticprint(what:Rest<Dynamic>):Void
Converts one or more arguments of any type to string in the best way possible and prints them to the console.
Note: Consider using godot.GD.pushError
and godot.GD.pushWarning
to print error and warning messages instead of godot.GD.print
.
This distinguishes them from print messages used for debugging purposes,
while also displaying a stack trace when an error or warning is printed.
var a = new int[] { 1, 2, 3 };
GD.Print("a", "b", a); // Prints ab[1, 2, 3]
Parameters:
what | Arguments that will be printed. |
---|
staticprintErr(what:Rest<Dynamic>):Void
Prints one or more arguments to strings in the best way possible to standard error line.
GD.PrintErr("prints to stderr");
Parameters:
what | Arguments that will be printed. |
---|
staticprintRaw(what:Rest<Dynamic>):Void
Prints one or more arguments to strings in the best way possible to console. No newline is added at the end.
Note: Due to limitations with Godot's built-in console, this only prints to the terminal.
If you need to print in the editor, use another method, such as godot.GD.print
.
GD.PrintRaw("A");
GD.PrintRaw("B");
// Prints AB
Parameters:
what | Arguments that will be printed. |
---|
staticprintS(what:Rest<Dynamic>):Void
Prints one or more arguments to the console with a space between each argument.
GD.PrintS("A", "B", "C"); // Prints A B C
Parameters:
what | Arguments that will be printed. |
---|
staticprintT(what:Rest<Dynamic>):Void
Prints one or more arguments to the console with a tab between each argument.
GD.PrintT("A", "B", "C"); // Prints A B C
Parameters:
what | Arguments that will be printed. |
---|
staticpushError(message:String):Void
Pushes an error message to Godot's built-in debugger and to the OS terminal.
Note: Errors printed this way will not pause project execution. To print an error message and pause project execution in debug builds, use [code]assert(false, "test error")[/code] instead.
GD.PushError("test_error"); // Prints "test error" to debugger and terminal as error call
Parameters:
message | Error message. |
---|
staticpushWarning(message:String):Void
Pushes a warning message to Godot's built-in debugger and to the OS terminal.
GD.PushWarning("test warning"); // Prints "test warning" to debugger and terminal as warning call
Parameters:
message | Warning message. |
---|
staticrandRange(from:Float, to:Float):Float
Returns a random floating point value on the interval between from
and to
(inclusive).
GD.PrintS(GD.RandRange(-10.0, 10.0), GD.RandRange(-10.0, 10.0)); // Prints e.g. -3.844535 7.45315
Returns:
A random double
number inside the given range.
staticrandSeed(seed:UInt64, newSeed:Out<UInt64>):UInt
Returns a random unsigned 32-bit integer, using the given seed
.
The newSeed
will return the new seed.
Parameters:
seed | Seed to use to generate the random number. |
---|---|
newSeed | Seed used by the random number generator. |
Returns:
A random uint
number.
staticrandf():Single
Returns a random floating point value between 0.0
and 1.0
(inclusive).
GD.Randf(); // Returns e.g. 0.375671
Returns:
A random float
number.
staticrandi():UInt
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).
GD.Randi(); // Returns random integer between 0 and 2^32 - 1
GD.Randi() % 20; // Returns random integer between 0 and 19
GD.Randi() % 100; // Returns random integer between 0 and 99
GD.Randi() % 100 + 1; // Returns random integer between 1 and 100
Returns:
A random uint
number.
staticrandomize():Void
Randomizes the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time.
Note: This method is called automatically when the project is run.
If you need to fix the seed to have reproducible results, use godot.GD.seed
to initialize the random number generator.
staticrange(end:Int):IEnumerable_1<Int>
staticRange(start:Int, end:Int, step:Int):IEnumerable_1<Int>
staticRange(start:Int, end:Int):IEnumerable_1<Int>
Returns a cs.system.collections.generic.IEnumerable
1 that iterates from
0 to
end in steps of
1`.
Parameters:
end | The last index. |
---|
staticseed(seed:UInt64):Void
Sets seed for the random number generator.
Parameters:
seed | Seed that will be used. |
---|
staticstr(what:Rest<Dynamic>):String
Converts one or more arguments of any type to string in the best way possible.
Parameters:
what | Arguments that will converted to string. |
---|
Returns:
The string formed by the given arguments.
staticstr2Var(str:String):Dynamic
Converts a formatted string that was returned by godot.GD.var2Str
to the original value.
string a = "{\"a\": 1, \"b\": 2 }";
var b = (Godot.Collections.Dictionary)GD.Str2Var(a);
GD.Print(b["a"]); // Prints 1
Parameters:
str | String that will be converted to Variant. |
---|
Returns:
The decoded Variant
.
statictypeExists(type:String):Bool
Returns whether the given class exists in godot.ClassDB
.
Returns:
If the class exists in godot.ClassDB
.
staticinlinevar2Bytes(var_:Dynamic, ?fullObjects:Bool):Array<UInt8>
Encodes a Variant
value to a byte array.
If fullObjects
is true
encoding objects is allowed
(and can potentially include code).
Deserialization can be done with godot.GD.bytes2Var
.
Parameters:
var | Variant that will be encoded. |
---|---|
fullObjects | If objects should be serialized. |
Returns:
The Variant
encoded as an array of bytes.
staticvar2Str(var_:Dynamic):String
Converts a Variant
var
to a formatted string that
can later be parsed using godot.GD.str2Var
.
var a = new Godot.Collections.Dictionary { ["a"] = 1, ["b"] = 2 };
GD.Print(GD.Var2Str(a));
// Prints
// {
// "a": 1,
// "b": 2
// }
Parameters:
var | Variant that will be converted to string. |
---|
Returns:
The Variant
encoded as a string.