How to use load_resource_pack?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

For example:

Globals.load_resource_pack("res://Scripts.pck")
print(load("res://TestingPackFile.gd")) No idea..   

I exported a TestingPackFile.gd to Scripts.pck. So now I am trying to load that .pck file by using the load_resource_pack method, but when I use load it’s still returning [Object:null].

I think I am doing this wrong? :frowning: I couldn’t find any documentation on this so I am sorry.

print(Globals.load_resource_pack("res://Scripts.pck")) does return a bool which is true. So I know it does get loaded… Hmmm?

:bust_in_silhouette: Reply From: Skrylar

You don’t want to use a res:// URL to load resource packs. Loading files through res:// has a special meaning in Godot, depending on whether or not you have deployed the game with a packfile or not. If you are running in the editor, or without a packfile, then res:// files are located in the same directory as the game engine or below. When a packfile is present (the data.pck stuff) the engine will instead look almost exclusively in that file to find resources. This is a “virtual filesystem” and is very common in game development.

When you have deployed the game and used res://stuff.pck it will try to find the packfile inside the game’s packfile, when it’s most likely not there (and there is no benefit to recursing packfiles.) You will want to use an actual filepath (such as without the res:// bit) or some file functions to get a real path.

I have code like this which demonstrates everything (at least on 2.1, in the editor):

func pack():
	var image = ResourceLoader.load("image.png")
	ResourceSaver.save("image.tex", image, ResourceSaver.FLAG_COMPRESS)
	var pack = PCKPacker.new()
	pack.pck_start("dlc.pck", 4)
	pack.add_file("res://qwop.tex", "image.tex")
	pack.flush(true)

func use():
	Globals.load_resource_pack("dlc.pck")

func _ready():
	use()
	var x = ResourceLoader.load("res://qwop.tex")
	print(x)

Qwop doesn’t exist in the workspace, it only exists inside the packfile that is created by a call to pack on previous runs. But when the package is mounted, then its contents are made available as though the game was built with it all along. I don’t think the engine devs have had to deal with DLC straight-on (the GUI isn’t really built for it) but you can manually implement it (or with editor plugins, a helper to pack DLC I guess.)

Look at this too, I have managed to load levels exported with the export option, without the use of pckpacker.

Downloadable Content Access (DLC) [SOLVED] - Archive - Godot Forum

eons | 2017-02-07 12:26