Hello, I have a zip file containing 1 file : Level_0__Tiles.png

func _ready() -> void:
	assert(ProjectSettings.load_resource_pack("user://png2.zip"))

	print(load("res://Level_0__Tiles.png"))
	print(load("user://Level_0__Tiles.png"))
	print(load("import/Level_0__Tiles.png"))
	print(load("Level_0__Tiles.png"))

This code prints the following:

[Object:null]
[Object:null]
[Object:null]
[Object:null]

What am I doing wrong? How am I supposed to access the files loaded? There's no documentation about it and I tried everything I could find on forums.

you are printing in the ready, which is called just once, the resources have likely had no time to load.

Same thing happens on a button signal that I press 10sec later:

func _ready() -> void: 
	assert(ProjectSettings.load_resource_pack("user://png2.zip"))
	a = load("res://Level_0__Tiles.png")
	b = load("user://Level_0__Tiles.png")
	c = load("import/Level_0__Tiles.png")
	d = load("Level_0__Tiles.png")

func _on_LevelBtn_pressed() -> void:
	print(a)
	print(b)
	print(c)
	print(d)

[Object:null]
[Object:null]
[Object:null]
[Object:null]

oh, hold on it's a png, not a godot resource such as .tex, that might be your problem.

When I load a png from outside the zip, it looks OK: [StreamTexture:1349] When I load a gd from inside the zip, it looks OK: [GDScript:10924]

I guess the load_resource_pack() works only on some filetypes. I think I'll switch to C#

ProjectSettings.load_resource_pack() is meant to be used with PCKs or ZIPs exported using PCKPacker. Using it with self-created ZIP archives is not officially supported. For a proper ZIP reading/writing API, you'd need to use https://github.com/godotengine/godot/pull/34444 instead (which isn't merged yet as of writing).

You may be able to load the PNG file directly using the File class, then use Image's load_png_from_buffer() function to create an image at run-time.

7 months later