Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProjectSettings.load_resource_pack overrides files in the main project if replace_files is false. #89299

Closed
m4rr5 opened this issue Mar 8, 2024 · 3 comments · Fixed by #90425
Milestone

Comments

@m4rr5
Copy link
Contributor

m4rr5 commented Mar 8, 2024

Tested versions

Reproducible in 4.2.1-stable.

System information

Godot v4.1.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1050 (NVIDIA; 31.0.15.2879) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

I'm trying to load a resource pack from a zip file using ProjectSettings.load_resource_pack() with the replace_files boolean set to false, but regardless the script file in the zip, which has the same name as an identical script in the main project, is being replaced.

Steps to reproduce

Open and run the sample project. It prints the following lines to the output window:

plugin loaded
hello from the plugin

That last line means it executed the hello() function from the res://Plugin.gd script in the plugin.zip. I would expect it to use the function from the same script that is already present in the main project.

Minimal reproduction project (MRP)

This is the project to reproduce the issue. It contains a plugin.zip which is exported from a second project which is listed here as the second file. You don't need it to reproduce the issue, but it's included in case you want to re-generate plugin.zip yourself.
godot-host.zip
godot-plugin.zip

@rburing
Copy link
Member

rburing commented Mar 9, 2024

The problem seems to be that res://Plugin.gd was never loaded from the main project, so as far as the current code is concerned there is no replacement going on. The following works the way you expect:

func _ready():
	load("res://Plugin.gd")
	if ProjectSettings.load_resource_pack("res://plugin.zip", false):
		print("plugin loaded")
		var script := load("res://Plugin.gd")
		var instance = script.new()
		instance.hello()

While I do understand it, it seems quite unintuitive to me, so either the replace_files option needs to be documented a lot better, or the behavior needs to be fixed.

@m4rr5
Copy link
Contributor Author

m4rr5 commented Mar 9, 2024

Thanks for the example. I would argue it's a little more than "unintuitive" as the documentation implies that if replace_files is false that whatever files are in the main project would never be replaced. Furthermore, if I take your modified example above and make it:

func _ready():
	load("res://Plugin.gd")
	if ProjectSettings.load_resource_pack("res://plugin.zip", true):
		print("plugin loaded")
		var script := load("res://Plugin.gd")
		var instance = script.new()
		instance.hello()

Note that I've changed replace_files to true. In this case it still invokes the script from the main project. That being the case, what does that replace_files parameter actually do?

@tracefree
Copy link
Contributor

Hi, I think I know what causes this. Because the resource folder is treated differently from packs when running the game from the editor, replace_files can only affect files from previously loaded packs. In exported projects the resource folder is in a pack, so the problem shouldn't arise there.
I'm also working on a PR that seems to solve this problem in the editor as well according to my testing.

Godot's console showing "plugin loaded hello from the main project"

@AThousandShips AThousandShips added this to the 4.3 milestone Apr 12, 2024
@AThousandShips AThousandShips modified the milestones: 4.3, 4.4 May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants