Load_resource_pack doesnt overwrite class

Godot Version

4.3

Question

I’m trying to figure out how to create patches.

As an example, I have a main.tscn as the main scene and an add_class.gd file.

With the patch, the add_class.gd file should be replaced, but the text of the label is still set to “original” after starting the game.
What am I doing wrong?

main.gd:

extends Node2D

func _ready() -> void:
	ProjectSettings.load_resource_pack("res://patch.pck")
	
	Add_Class.change($Label)

add_class.gd:

extends Node

class_name Add_Class

static func change(lbl: Label) -> void:
	lbl.text = 'original'

add_class.gd in patch.pck:

extends Node

class_name Add_Class

static func change(lbl: Label) -> void:
	lbl.text = 'patched'

Never worked with resource packs but my understanding is that the contents of the package are loaded into the resource tree and you then have to (re) load those resources.
So, can you try var Add_Class = load("add_class.gd") to your main.gd after you loaded the package?

PS: You do know that “Add_Class” isn’t following the style guide?

I’ve since discovered that already loaded resources are not overwritten.
Since the class is global, it becomes tricky. The var Add_Class wouldn’t be automatically available throughout the game under that name; instead, you’d have to, for example, set the variable via an autoload and then always call Autoload.Add_Class.change(…).

I’ve put this issue on hold for now until I figure out the best approach. It’s very convenient to rely on autocompletion, but when patching the game I don’t really want to have to re-download the entire pck file just because one script has changed.

The annoying part is that when exporting the game, the dependencies are bundled along as well. So, no matter how you do it, all the autoloads and classes will always be included.
But perhaps I’m overthinking it—the real weight comes only from the audio/image files. I still need to test how to avoid having them included as dependencies in the scenes, probably using load().

PS: Yes, I know I’m not exactly sticking to the guide, but since I work solo and have my own idea of nicely, readable code (the example codes here were just thrown together quickly), at least for this project I’ll stick to my own style. But thanks for the hint

1 Like