godotengine / godot

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

ResourceLoader does not find resource when using binary .res format and supplying a type hint. #96494

Open simonschreibt-code opened 2 months ago

simonschreibt-code commented 2 months ago

Tested versions

v4.3.stable.official [77dcf97d8]

System information

Godot v4.3.stable - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce GTX 1070 (NVIDIA; 32.0.15.5612) - AMD Ryzen 7 1700X Eight-Core Processor (16 Threads)

Issue description

When I supply a type hint AND use a binary format for the ResourceLoader, it can't find the resource. The returned error:

E 0:00:01:0649   game.gd:16 @ _ready(): Resource file not found: user://savefile.res (expected type: Savegame)
  <C++ Error>    Condition "!file_check->file_exists(p_path)" is true. Returning: Ref<Resource>()
  <C++ Source>   core/io/resource_loader.cpp:288 @ _load()
  <Stack Trace>  game.gd:16 @ _ready()

Here is my code:

func _ready() -> void:
    # WORKS 1: 
    # Filetype .tres
    # You can add a Type Hint for ResourceLoader or not, both works
    var my_savegame : Savegame = Savegame.new()
    ResourceSaver.save(my_savegame, "user://savefile.tres")
    my_savegame = ResourceLoader.load("user://savefile.tres", "Savegame")

    # Does NOT work! Error: _ready(): Resource file not found: user://savefile.res (expected type: Savegame) 
    # Filetype .res (binary)
    # Type Hint for ResourceLoader (if you remove the type hint, it works!)
    ResourceSaver.save(my_savegame, "user://savefile.res")
    my_savegame = ResourceLoader.load("user://savefile.res", "Savegame")

Steps to reproduce

  1. Open the Project

  2. Press play

  3. Look at the Error log

  4. Then open game.gd

  5. remove the type hint in line 16

  6. Press play again

  7. Now it will work, no error dropped

Minimal reproduction project (MRP)

test_resourceloader_hint.zip

fire commented 2 months ago

What happens if you use "Savegame" as the type?

simonschreibt-code commented 2 months ago

What happens if you use "Savegame" as the type?

I just added the code I use to the main post. There you can see that it does NOT work, when I add "Savegame" as type hint when using binary .res format.