+1 vote

Hello! Does anybody know using GDScript to access outside the project folder to open files and other materials that can be used as a secondary addon, aka DLC

I know that there is a way in GDScript that we can use a certain command to access a certain folder in a PC or MAC to get to the external folder that exists outside the game, which maybe it can be useful for installing mods or addons?

It's nothing important or critical but it was a good question with a good example answer that was lost due to the replacement of the old Godot Forums with the new one.

For example let's say my addon folder is located in "C://[USER]/game_location/addons" and I wanted to access the mod folder containing extra TSCN and TRES files necessary to implement the addon...

asked Nov 9, 2016 in Engine by Corruptinator (198 points)
edited Nov 29, 2016 by Corruptinator

I can tell you just this (my answer).
https://godotengine.org/qa/8667/how-easy-is-it-to-decompile-a-data-pck-file

On top of that, heard that Godot 3 will improve some things, also change all the way projects work (won't be compatible with 2), maybe making easier multi-package, patch, dlc and mods.

1 Answer

+1 vote
Best answer

Finally figured it out...

Is just:

Globals.load_resource_pack(path_to_pack)

Where path_to_pack could be res://file_name.pck, user://file_name.pck , maybe external files too.

Resources will be accesible as if these were on the game virtual filesystem (from res://), not sure what happens with files with the same name (I think new files overwrite/override older ones).

Export to a zip first to know the name changes if making binary conversions/compressions/encryption (files are renamed, like scene.tscn.converted.scn)


It may be possible to create/modify a pck file with PCKPacker but not sure.

answered Nov 28, 2016 by eons (7,764 points)
selected Nov 29, 2016 by Corruptinator

Thanks! I'll check it out and see if it works.

P.S. What about loading external PCKs? isn't there a command that allows that to bring in files from outside the executable game file?

It actually works! here is the code:

Globals.load_resource_pack(Globals.globalize_path("res://"+"DLC/"+"DLC1.pck"))
var data = load("res://Test.tscn.converted.scn").instance()
add_child(data)

(NOTE: globalize_path command does allow the godot to load files externally since it quickly uses the "res://" to bring up the location of the computer folder on the OS.

EX: globalize_path("res://") = "C:/[User]/[Username]/Godot/[Project]"

I don't know yet what happens if new resources have autoloads (since engine config is overwritten if packed with the editor), could be interesting if these could be added.

Also, Resource.take_over_path might be useful to rename/overwrite resources after loading them.

Note: As of Godot 3, load_resource_pack function resides in ProjectSettings class

Doc link: https://docs.godotengine.org/en/latest/classes/class_projectsettings.html#class-projectsettings-method-load-resource-pack

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 How to use this Q&A? before posting your first questions.