Skip to reading
GDScript Programming & Godot

33. How to access Godot functionality

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
Code example
func run() -> Dictionary:
    var information: Dictionary = Engine.get_version_info()
    var elapsed_ms: int = Time.get_ticks_msec()
    var position: Vector3 = Vector3(2, 0, -1)
    return {
        "godot": information.get("string", ""),
        "elapsed_ms": elapsed_ms,
        "distance": position.length()
    }

No extra import is needed for built-in Godot classes and singletons. You can call Time, Engine, Input, FileAccess, ResourceLoader, ClassDB and the normal GDScript functions directly. Class names and method names keep Godot’s case and spelling.

Source table from 33. How to access Godot functionality, page 42
You need…Typical Godot route
A new nodeTimer.new(), Label.new(), Node3D.new()
A delayawait get_tree().create_timer(seconds).timeout
A signal callbacknode.signal_name.connect(callable)
An asset resourceload / ResourceLoader.load after checking the path
A new class from a filepreload or load a .gd Script, then new()
A native sceneload a PackedScene, then instantiate()
A runtime checkis_instance_valid, is, has_method, ClassDB queries

Access to the API is not automatic integration with PCA’s saved records. A native cube you create yourself is not automatically an adventure hotspot, a saved object or a navigation obstacle. Decide which system owns it.

Page 42 of 378Permalink
Go to page