Topic was automatically imported from the old Question2Answer platform.
Asked By
Delin
I’m making a pck file and putting the default icon.png in it this way
var pack = new PCKPacker();
pack.PckStart("dlc.pck", 4);
pack.AddFile("res://qwop.png", "icon.png");
pack.Flush(true);
ProjectSettings.LoadResourcePack("dlc.pck");
var sprite = new Sprite();
sprite.Texture = (Texture)ResourceLoader.Load("res://qwop.png");
AddChild(sprite);
Problem is when I load the “qwop.png” texture to a sprite I get this error
The TL;DR is that you need to treat “imported” and “not imported” files as separate things.
So the code you have looks fine until you call ResourceLoader.Load on the packed png and expect to get a Texture back. Instead, you would have to do the C# equivalent of this
var image = Image.new()
var texture = ImageTexture.new()
image.load('res://qwop.png')
texture.create_from_image(image)
sprite.texture = texture
This was one of the first and few topics I found on this so I figure I should add an answer here too - there’s a way to add images/sounds/etc via PCKPacker but it’s not straightforward, as noted here (and in my comment below).
The tl;dr is that you need to add .import files instead of the media files themselves, and then you need to add the dependencies of that .import file. You can use ConfigFile.load to read .import files and add the file paths listed in deps/dest_files via PCKPacker.add_file and then loading the resulting .pck file’s media resources should work.