ref.godot - jgrey4296/jgrey4296.github.io GitHub Wiki

Godot Reference

Packages Docs

Godot Engine

Overridable functionsc

  • _enter_tree
  • _exit_tree
  • _ready
  • _process
  • _physics_process
  • _unhandled_input
  • _input

Idle Processing

Physics

Rendering

Sound

2d

3d

Resource Loading

Input

Debugging

UI

Nodes

GdScript

Syntax

# Everything after "#" is a comment.
# A file is a class!

# (optional) icon to show in the editor dialogs:
@icon("res://path/to/optional/icon.svg")

# (optional) class definition:
class_name MyClass

# Inheritance:
extends BaseClass

# Member variables.
var a = 5
var s = "Hello"
var arr = [1, 2, 3]
var dict = {"key": "value", 2: 3}
var other_dict = {key = "value", other_key = 2}
var typed_var: int
var inferred_type := "String"

# Constants.
const ANSWER = 42
const THE_NAME = "Charly"

# Enums.
enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALLY}
enum Named {THING_1, THING_2, ANOTHER_THING = -1}

# Built-in vector types.
var v2 = Vector2(1, 2)
var v3 = Vector3(1, 2, 3)

# Functions.
func some_function(param1, param2, param3):
	const local_const = 5

	if param1 < local_const:
		print(param1)
	elif param2 > 5:
		print(param2)
	else:
		print("Fail!")

	for i in range(20):
		print(i)

	while param2 != 0:
		param2 -= 1

	match param3:
		3:
			print("param3 is 3!")
		_:
			print("param3 is not 3!")

	var local_var = param1 + 3
	return local_var

# Functions override functions with the same name on the base/super class.
# If you still want to call them, use "super":
func something(p1, p2):
	super(p1, p2)

# It's also possible to call another function in the super class:
func other_something(p1, p2):
	super.something(p1, p2)

# Inner class
class Something:
	var a = 10

# Constructor
func _init():
	print("Constructed!")
	var lv = Something.new()
	print(lv.a)

Keywords

Defined in gdscript_tokenizer.cpp.

  • abstract
  • as
  • and
  • assert
  • await
  • break
  • breakpoint
  • class
  • class_name
  • const
  • continue
  • elif
  • else
  • enum
  • extends
  • for
  • func
  • if
  • in
  • is
  • match
  • namespace
  • not
  • or
  • pass
  • preload
  • return
  • self
  • signal
  • static
  • super
  • trait
  • var
  • void
  • while
  • when
  • yield
  • INF
  • NAN
  • PI
  • TAU

Operators

Left Associative.

  • ( )
  • x[index]
  • x.attribute
  • foo()
  • await x
  • x is [not] Node
  • x is Node
  • x ** y
  • ~x
  • +x
  • -x
  • x * y
  • x / y : defaults to integer, not fractional
  • x % y
  • x + y
  • x - y
  • x [<<, >>] y
  • x [&, ^, |] y
  • x [==, !=, <, >, <=, >=] y
  • x [not] in y
  • not x
  • x [and, or] y
  • [expr] if [cond] else [expr]
  • x as Node
  • x [+, -, *, /, %, &, |, ^]= y
  • x [<<, >>]= y

Literals

  • null
  • false, true
  • 45
  • 0x8f51 : hex
  • 0b101010 : binary
  • 3.14, 58.1e-10 # floats
  • “strings”, r”strings”
  • ””“strings”“”, r”“”strings”“”
  • &”name” : string name
  • ^”node/label” : nodepath
  • $NodePath -> get_node(“NodePath”)
  • %UniqueNode -> get_node(“%UniqueNode”)

String escape sequences

\{} : [ntrabfv”’\] \uXXXX : UTF-16 code point \UXXXXXX : UTF-32 code point

Annotations/Decorators

To interact with engine/editor

@export_range(1, 100)
var ranged : int = 50

Dicts

var adict = {
   first  = "blah",
   second = 3,
   third  = [1,2,3],
}

Functions / Callables

# 'self' is always available
func example(a:int,b:str, c:="blah") -> bool:
	return false

var exfn : Callable = example

example(2,"bloo")
exfn.call(2, "bloo")
var a_lambda : Callable = func(x): print(x)
var b_lambda : Callable = func(x): return x + 2

a_lambda.call(2)
static func blah() -> void:
	print("blah")
func a_coroutine():
	print("blah")
	# Waits until the signal is emitted:
	await $ANode.a_signal
	return true

# Somewhere else:
var result = await a_coroutine()
# will error:
var other = a_coroutine()
# not needing the result does need await:
a_coroutine()

Variables

var myvar : int = 2
# Or declared + initialized:
var my_vec := Vector2()
# Belongs to class, not instance:
static var blah : int = 5

# Constants
const name : str = "blah"
var myvar : int = 2
var example : int :
	get:
		return -myvar
	set(value):
		myvar = -value
var mynode: Node2D
mynode = $Sprite2D as Node2D
# results in 'null' if it fails

Classes

class_name Blah
extends Node
# extends "res://path/to/something.gd"

func _init():
	pass
class MyClass:
	var example : int = 1

class Sub extends MyClass:
	pass

Enums

enum {FIRST, SECOND, THIRD}
enum MyEnum {a, b, c}

FIRST
MyEnum.a

Control Flow

if (false):
    pass
elif (true):
	pass
else:
	pass
while (false):
	# continue
	# break
	pass
for x:int in [1,2,3,4]:
	pass

var d = {"a":2,"b":3}
for x:str in d:
	print(d[x])

for x:int in range(1,5):
	pass
var myval : int = 5
match myval:
	5:
		pass
	4,3:
		pass
	var x when x > 2:
		pass
	[]:
		pass
	[1,2,3]:
		pass
	[var x, var y]:
		pass
	{"name":"blah"}:
		pass
	_:
		print("default")
var i : int = 4
assert(i == 0, "val was not zero")

Types

Annotations

  • @onready
  • @static_unload : must be at very top of script
  • @tool : to run scripts inside the editor
  • @deprecated
  • @experimental

Exports

  • @export_group(“group name”)
  • @export_category(“name”)
  • @export
  • @export_range
  • @export_exp_easing
  • @export_color_no_alpha
  • @export_flags
  • @export_flags_2d_physics
  • @export_flags_2d_render
  • @export_flags_2d_navigation
  • @export_flags_3d_physics
  • @export_flags_3d_render
  • @export_flags_3d_navigation
  • @export_storage
  • @export_custom
  • @export_tool_button
  • @export_file
  • @export_dir
  • @export_global_file
  • @export_multiline

Std Functions

  • typeof(x)

Tool Mode

Memory Management

free($aNode)
queue_free($aNode)

Signals

# An observer callback, in aNode:
signal my_signal(val)

# Somewhere else:

func my_fun(val):
	pass

$aNode.my_signal.connect(my_fun)

# Back in aNode:
my_signal.emit(2)

Init Order

  1. null initialization
  2. top to bottom, normal values
  3. _init()
  4. exported values assigned
  5. @onready
  6. _ready()

Shaders

Syntax

types

builtin functions

preprocessor

Spatial

Canvas Item

Particle

Sky

Fog

CSharp

GDExtensions

Rust Extension

Android

Links

⚠️ **GitHub.com Fallback** ⚠️