Skip to reading
GDScript Programming & Godot

34. Keep the PCA base when extending a script

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
extends "res://scripts/runtime/script_base.gd"
Code example
func run() -> String:
    Log("The PCA helpers are still inherited.")
    return get_class()

This explicit base path is equivalent to keeping PCA’s script base. Omitting extends also lets PCA add it. Writing extends Node creates a plain Node script; it does not inherit PCAScriptBase, so bare Say, Action, Variable and other inherited helpers are no longer supplied.

A PCA record must instantiate as a Node. A standalone Resource or RefCounted helper is useful, but it belongs inside a helper class/resource file or as an inner class, not as the root class of a PCA native record.

To add spatial behavior while keeping the adventure base, create a Node3D child or a helper class instance. GDScript has single inheritance. You cannot extend PCAScriptBase and Node3D as two separate parents.

Do not redeclare Runtime, context, player or this on a script that already inherits the PCA base. On a deliberately plain Node extension, only explicitly present Runtime/context properties can be injected by the router.

Page 43 of 378Permalink
Go to page