-
-
Notifications
You must be signed in to change notification settings - Fork 1
Overriding Classes
Ryhon edited this page Dec 31, 2024
·
1 revision
Important
Due to an issue with Godot, scripts with a class_name
can be overriden ONLY ONCE.
See godot#83542 and godot-mod-loader#338
Overriding a script lets you change it's behavior simply by creating a subclass and taking over it's filesystem path.
The superclass must be the absolute path to the script, instead of it's class name.
Example script override:
res://mods/MyMod/Main.gd
:
extends Node
func _ready():
var script = load("res://mods/MyMod/Weapon.gd")
script.reload() # compile the script
var parentScript = script.get_base_script()
script.take_over_path(parentScript.resource_path)
res://mods/MyMod/Weapon.gd
:
extends "res://Scripts/Weapon.gd"
func PlayFireAudio():
base() # Calls Weapon.gd's PlayFireAudio
print("Pew!")