Load() not working on Web Export

Godot Version

Godot 4.3 (Stable)

Question

TLDR at the bottom

Hey! I’ve been using Godot for a while, and I have wanted to share my games in a way anyone can play, without having to send files to them. The web export is the perfect thing, although when I joined, I struggled to put my game anywhere because of the whole Shared Buffer Array thing. I was really excited for 4.3, as I heard single thread web exports are back.

I made my game and went to export it to the web. When I double-clicked the index.html file, it opened, but failed to fetch. I researched online and found I needed to host a local server to serve it to my self (found this, and I also used the Godot built-in remote debug feature). So I set it up and ran it. It worked great, except for one thing.

I would run my game, the main menu would show up. I would click start, and the first level would load, but none of the assets loaded by that scene would load. I think this is because to load the scenes, I use preload and store them in a dictionary, as I don’t have that many scenes, but to load the level and assets I use load() function to loop through a list of the assets. The load() function, FileAccess, ResourceLoader.load(), and DirAccess all don’t work, although preload() does. I could use preload to work around this, but ideally I wouldn’t need to. This is either a Github level bug, or just me being bad at exports.

I get a few errors, shown here:

E 0:00:00:0188   get_process_id: OS::get_process_id() is not available on the Web platform.
  <C++ Error>    Method/function failed. Returning: 0
  <C++ Source>   platform/web/os_web.cpp:128 @ get_process_id()

Custom error for when the FileAccess comes back null:

E 0:00:02:0715   main.gd:43 @ loadLevel(): Error Loading Level 1
  <C++ Source>   core/variant/variant_utility.cpp:1092 @ push_error()
  <Stack Trace>  main.gd:43 @ loadLevel()
                 main.gd:28 @ startFromSave()

The code for the error above:

func loadLevel(level: int, unload: Array ) -> void:
	currentLevel = level
	loadScene(unload, ["game"])#unload the 'unload' and load in a new game
	var file = FileAccess.open("res://Levels/" + str(level) + ".txt", FileAccess.READ) #Get the level file
	if file:
		var Loadedlevel = file.get_as_text(true)#get the file as text
		get_node("Game/Grid").loadLevel(evaluateString(Loadedlevel))#Convert String to Dictionary and load it into the new game scene
		file.close()
	else:
		push_error("Error Loading Level " + str(level))#no level to load/error opening it

A moment ago, I added a little bit of script (
+ ". Error: " + str(FileAccess.get_open_error()
) to get the error from the loading, and it throws Error: 7, which I think is ERR_FILE_NOT_FOUND.

On the web platform, using Chrome developer tools (saved as a log file, converted to a text file, and pasted here):

index.js:459 Godot Engine v4.3.stable.official.77dcf97d8 - https://godotengine.org
index.js:459 OpenGL API OpenGL ES 3.0 (WebGL 2.0 (OpenGL ES 3.0 Chromium)) - Compatibility - Using Device: WebKit - WebKit WebGL
index.js:474 USER ERROR: Error Loading Level 1
onPrintError @ index.js:474
put_char @ index.js:9
write @ index.js:9
write @ index.js:9
doWritev @ index.js:9
_fd_write @ index.js:9
$func24155 @ 0a418b96:0x19ad861
$func9000 @ 0a418b96:0x73a546
$func6058 @ 0a418b96:0x49086c
$func32189 @ 0a418b96:0x1b3d7bb
$func8512 @ 0a418b96:0x6b6b4d
$func32194 @ 0a418b96:0x1b3ddab
$func32187 @ 0a418b96:0x1b3d6a9
$func339 @ 0a418b96:0x411ef
$func391 @ 0a418b96:0x49264
$func9308 @ 0a418b96:0x761d0f
$func25952 @ 0a418b96:0x1a2acf1
$func4908 @ 0a418b96:0x3a6a23
$func1600 @ 0a418b96:0x16220d
$func46119 @ 0a418b96:0x21b67c4
$func7607 @ 0a418b96:0x5ced0a
$func4909 @ 0a418b96:0x3a6b1c
$func1600 @ 0a418b96:0x157f45
$func46119 @ 0a418b96:0x21b67c4
$func7607 @ 0a418b96:0x5ced0a
$func863 @ 0a418b96:0x9a0b8
$func19980 @ 0a418b96:0x108bf71
$func57811 @ 0a418b96:0x23de4ec
$func19742 @ 0a418b96:0x106feaa
$func57249 @ 0a418b96:0x23bc839
$func6392 @ 0a418b96:0x4be22f
$func4358 @ 0a418b96:0x32c1be
$func5262 @ 0a418b96:0x3fa3ce
$func19860 @ 0a418b96:0x107c46e
$func4356 @ 0a418b96:0x32be8b
$func863 @ 0a418b96:0x9a020
$func18567 @ 0a418b96:0xfdf5cd
$func50564 @ 0a418b96:0x22c0848
$func6399 @ 0a418b96:0x4bfbc0
$func2770 @ 0a418b96:0x240343
$func56822 @ 0a418b96:0x23b1db1
button_cb @ index.js:9
index.js:474    at: push_error (core/variant/variant_utility.cpp:1092)
onPrintError @ index.js:474
put_char @ index.js:9
write @ index.js:9
write @ index.js:9
doWritev @ index.js:9
_fd_write @ index.js:9
$func24155 @ 0a418b96:0x19ad861
$func9000 @ 0a418b96:0x73a546
$func6058 @ 0a418b96:0x49086c
$func32189 @ 0a418b96:0x1b3d7bb
$func8512 @ 0a418b96:0x6b6b4d
$func32194 @ 0a418b96:0x1b3ddcc
$func32187 @ 0a418b96:0x1b3d6a9
$func339 @ 0a418b96:0x411ef
$func391 @ 0a418b96:0x49264
$func9308 @ 0a418b96:0x761d0f
$func25952 @ 0a418b96:0x1a2acf1
$func4908 @ 0a418b96:0x3a6a23
$func1600 @ 0a418b96:0x16220d
$func46119 @ 0a418b96:0x21b67c4
$func7607 @ 0a418b96:0x5ced0a
$func4909 @ 0a418b96:0x3a6b1c
$func1600 @ 0a418b96:0x157f45
$func46119 @ 0a418b96:0x21b67c4
$func7607 @ 0a418b96:0x5ced0a
$func863 @ 0a418b96:0x9a0b8
$func19980 @ 0a418b96:0x108bf71
$func57811 @ 0a418b96:0x23de4ec
$func19742 @ 0a418b96:0x106feaa
$func57249 @ 0a418b96:0x23bc839
$func6392 @ 0a418b96:0x4be22f
$func4358 @ 0a418b96:0x32c1be
$func5262 @ 0a418b96:0x3fa3ce
$func19860 @ 0a418b96:0x107c46e
$func4356 @ 0a418b96:0x32be8b
$func863 @ 0a418b96:0x9a020
$func18567 @ 0a418b96:0xfdf5cd
$func50564 @ 0a418b96:0x22c0848
$func6399 @ 0a418b96:0x4bfbc0
$func2770 @ 0a418b96:0x240343
$func56822 @ 0a418b96:0x23b1db1
button_cb @ index.js:9

TLDR; When exporting to the web using either Godot’s built-in remote debug feature or a python localhost server, almost all functions used for loading files don’t work, except for preload().

I have looked at almost every page relating to this topic on the front page of Google looking for an answer. If anyone has any ideas, or you need something else, let me know.

Thanks!

There are certain file types which by default are not included in exports, and I believe *.txt is one of those types. You may have to explicitly add it to your export preset (in the “Filters to export non-resource files/folders” under the “Resources” tab) in order to get your level files into the export.

Relevant documentation:

I can’t seem to figure out how to change it, and I also load PNG files too in a different script.

EDIT: I figured it out, added *.png, *.txt and re-exported it. When I tried it again with python, nothing changed, although when I use the built-in remote-debug button, it loads and works just fine. Because of this, I will continue to keep it in template.

Either way, the OS.get_process_id() error still shows.

UPDATE 2: After some more testing, the python launch now throws errors in the browser, to the point where it won’t load. The built-in remote-debug (RD) loads the project, although I get two new errors for each piece I try to load:

E 0:00:05:0084   Grid.gd:38 @ createPentomino(): Cannot open file 'res://Piece Scenes/I.tscn'.
  <C++ Error>    Condition "err != OK" is true. Returning: Ref<Resource>()
  <C++ Source>   scene/resources/resource_format_text.cpp:1367 @ load()
  <Stack Trace>  Grid.gd:38 @ createPentomino()

and

E 0:00:05:0085   Grid.gd:38 @ createPentomino(): Failed loading resource: res://Piece Scenes/I.tscn. Make sure resources have been imported by opening the project in the editor at least once.
  <C++ Error>    Condition "found" is true. Returning: Ref<Resource>()
  <C++ Source>   core/io/resource_loader.cpp:284 @ _load()
  <Stack Trace>  Grid.gd:38 @ createPentomino()

Other than this, I think it works.

Ok, a little more research later, I figured out I was passing in a capital letter name into a lowercase file name. I fixed it, and now it works in the RD, albeit with a lot of lag. Unfortunately, the python script still does not work.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.