+1 vote

I'm trying to implement a mod manager in the game and I'm in a bit of trouble...
I am loading a zip folder with a ProjectSettings.loadresourcepack() command. once the mod is loaded, I am trying to replace the previous file with the new one. For example:

var scene = preload("res://ship/myship.tscn")
var modifiedScene = scene.instance()
var new node =  # a new created node

ModLoader.appendNodeInScene(modifiedScene, new node)
ModLoader.saveScene(modifiedScene, "res://ship/myship.tscn")

This code is working well, and I don't have any problem with it. But in another case, I'm trying to only replace a script. and in this case the same method doesn't seem to work:

func takeOverScript(newScriptPath:String, OldScriptPath:String):
    var savedScript = load(newScriptPath)

Once I'm calling this function, the OldScriptPath does have the code of the new script. Yay ! However, when I'm using a scene ( let call it myShypyard.tscn) with an external reference to my OldScriptPath:

[ext_resource path="res:///old/Script/Path.gd" type="Script" id=1]

The OLD script is called (I checked with some print, and the scene return the print of the old script and not the new one).

I even tried to use the same method as previously by loading an already modified copy of myShypyard.tscn, pointing to a new path, where I store the new script at first (res:///overwride/old/Script/Path.gd), but it's STILL the initial copy of the scene who is loaded, and not the new one.
I think godot is preloading my scene, and I can't find a way to reload it in the cache, or with my new scene, or with my new script...
Does somebody have an idea of how to make the script replace the old one at runtime ?
Or does anybody have a way to add a patch package BEFORE the game compilation ?

Godot version 3.3.2
in Engine by (17 points)
edited by

1 Answer

0 votes

I found the solution with some help. Obvious, yet not intuitive:
The script was used in a sub-nod of a preloaded screen. So once I overwrited the file, the game ALREADY preloaded the scene that was gonna use it during compilation time.

by (17 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.