Reloading script from DLC pck file

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By socomajor

Hello,

I am trying to make a game, which self-update.
I have a server with the up-to-date pck file for the entire game (it is small so it is OK to re-download it entirely when there is an update).
The game can detect that it has to reload the game (by comparing version number), and it downloads it into the “user://” filesystem.

When I load the game, it first run without knowing about the patch, so it loads the entire pck files that is next to the executable.
Then, it sees that “user://patch.pck” exists and loads it :

ProjectSettings.load_resource_pack("user://patch.pck")

"

The content of patch.pck should replace everything that was into the first pck.
But I have a script “Global.gd” that is not replaced…
I suspect this is because of the cache system for resources. Since it has already been loaded, it uses the cached version. But here, the desired behaviour is to replace it.

How would you do ?

Here is the code that loads the script (first in the ready function, and then “reset” is called after the patch.pck has been loaded. I see that nothing in the Global variable changes.

extends Node

var Global # Global variables that will be used by the game


func _ready():
	reset()


func reset():
	# I load the script
	var global_script = load("res://scripts/Global.gd")
	
	# I delete any previously loaded Global Node
	if has_node("Global"):
		remove_child(get_node("Global"))
		
	# I re-instance Global
	Global = global_script.new()
	Global.name = "Global"	
	add_child(Global, true)
:bust_in_silhouette: Reply From: Prometheus1998

The easiest way to deal with this that I can see is to isolate all game assets (scripts, nodes, et cetera) from the auto-updater stuff, so only the auto-updater is loaded into the resource cache and you don’t need to reload anything.

If you want to be able to release updated versions of the auto-updater as well, you could have the update checker download an ‘update.exe’, launch that, and close the game’s executable once the update.exe is running. The ‘update.exe’ file can then override the entire game with new files without interference.

The alternative is to use something like Steam (charges $100 as a ‘processing fee’ to even get it reviewed for the platform) or Itch.io (no fees and you decide how much of each sale they get), and allow the third-party launcher to keep the game up-to-date.