Skip to reading
GDScript Programming & Godot

48. Inheritance, annotations and editor code

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
class Charge:
    var amount: int = 10
    func description() -> String:
        return "Charge: " + str(amount)
Code example
class FullCharge extends Charge:
    func description() -> String:
        return super.description() + " (ready)"
Code example
func run() -> String:
    return FullCharge.new().description()

A subclass can override a parent method. super calls the parent implementation. Keep an override’s signature compatible with the inherited method; replacing a base helper with a different parameter list can cause parser errors.

Godot annotations include @export, @onready, @tool, @warning_ignore and @rpc. @export creates a Godot Inspector property for a file-backed scene script; it does not automatically add a field to PCA’s custom record inspector. @onready runs at Godot ready time, which is still before PCA binds a newly added record instance.

@tool runs in the Godot editor context. The standalone PCA application is itself a running Godot application, not automatically a Godot EditorPlugin host. Custom PCA designer tools require an actual integration, not merely an @tool line.

Page 57 of 378Permalink
Go to page