godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.75k stars 20.85k forks source link

[4.3] ResourceLoader.load not working for dedicated_server #97467

Open jasonfma opened 1 week ago

jasonfma commented 1 week ago

Tested versions

System information

dedicated server built using MacOS M3 Pro - deployed ARM64

Issue description

I'm trying to load a script on start but it doesn't seem to be available when the app is built as a dedicated server.

Here is the offending line:

var version_file = ResourceLoader.load("res://scripts/version.gd", "", ResourceLoader.CACHE_MODE_IGNORE)

Error:

2024-09-25T19:12:07.983Z

ERROR: Attempt to open script 'res://scripts/version.gd' resulted in error 'File not found'.

2024-09-25T19:12:07.983Z

at: load_source_code (modules/gdscript/gdscript.cpp:1094)

2024-09-25T19:12:07.983Z

ERROR: Failed to load script "res://scripts/version.gd" with error "File not found".

2024-09-25T19:12:07.983Z

at: load (modules/gdscript/gdscript.cpp:2936)

When I change to using load, the error goes away. This isn't a viable workaround for me as I'm loading this file in a pck and need the updated version after loading the pck (i.e. no cache).

load("res://scripts/version.gd")

Steps to reproduce

  1. Load a script file using ResourceLoader.load(<script_file>, "", ResourceLoader.CACHE_MODE_IGNORE)
  2. build app as dedicated_server (arm64)
  3. run and see error

Minimal reproduction project (MRP)

resourceloaderissue.zip

matheusmdx commented 4 days ago

Bisecting points to #89005 as the culprit, @dalexeev

image


Note the error doesn't stop the script from load correctly:

With a valid script path:

ERROR: Attempt to open script 'res://test.gd' resulted in error 'File not found'.
   at: (modules\gdscript\gdscript.cpp:1033)
ERROR: Failed to load script "res://test.gd" with error "File not found".
   at: ResourceFormatLoaderGDScript::load (modules\gdscript\gdscript.cpp:2825)
<GDScript#-9223372013349894945> # Print from the result of ResourceLoader.load()

With a invalid script path:

ERROR: Attempt to open script 'res://tes.gd' resulted in error 'File not found'.
   at: (modules\gdscript\gdscript.cpp:1033)
ERROR: Failed loading resource: res://tes.gd. Make sure resources have been imported by opening the project in the editor at least once.
   at: (core\io\resource_loader.cpp:278)
ERROR: Error loading resource: 'res://tes.gd'.
   at: (core\core_bind.cpp:73)
<Object#null> # Print from the result of ResourceLoader.load()