"USER ERROR: Scene instance is missing" when export with release in Godot_v4.3-stable_mono

Godot Version

Godot_v4.3-stable_mono_win64

Question

After exporting my game using Export with Release, there is about a 20% chance that the following error will occur when opening a specific page:

USER ERROR: Cannot get class ''.
   at: _instantiate_internal (core/object/class_db.cpp:515)
USER WARNING: Node  of type  cannot be created. A placeholder will be created instead.
   at: instantiate (scene/resources/packed_scene.cpp:277)
USER ERROR: Cannot get class ''.
   at: _instantiate_internal (core/object/class_db.cpp:515)
USER WARNING: Node  of type  cannot be created. A placeholder will be created instead.
   at: instantiate (scene/resources/packed_scene.cpp:277)
USER ERROR: Cannot get class ''.
   at: _instantiate_internal (core/object/class_db.cpp:515)
USER WARNING: Node  of type  cannot be created. A placeholder will be created instead.
   at: instantiate (scene/resources/packed_scene.cpp:277)
USER ERROR: Scene instance is missing.
   at: instantiate (scene/resources/packed_scene.cpp:244)

I am using C# for development, and the error seems to be coming from the following code:

var packagedScene = ResourceLoader.Load<PackedScene>(path); 
var instance = packagedScene.Instantiate();

The issue is that during the development phase and when using Export With Debug, this problem never occurs, even after extensive testing. However, it only happens when using Export with Release.

I’m reaching out to see if anyone else has encountered this issue and found a solution, or if there are any specific things to watch out for when using Export with Release.

1 Like

你把path打印一下

I had the same problem with you. I tried create this piece of code.
Replace all the default ResourceLoader.Load() with my version and the problem went away.

public static class Utils {

    public static Dictionary<string, PackedScene> CachedScenes = new();

    public static T CreateInstanceFromScene<T>(string path) where T : Node {
        if (CachedScenes.ContainsKey(path) == false) {
            CachedScenes[path] = ResourceLoader.Load<PackedScene>(path, null, ResourceLoader.CacheMode.IgnoreDeep);
        }
        return CachedScenes[path].Instantiate<T>();
    }
}
3 Likes

Thanks for this - amazing! I’ve spent 8 hours diagnosing and searching the internet for anyone with a similar issue and finally found this post.

In my tests I have not seen the crash with your fix - I was getting the exact same issue as the OP in release mode only and your fix has worked!

Interesting how its around static memory and ignoring deep caching - I reached a similar conclusion only trying deep ignore with the cache to the .Load call which didn’t work.

I’m convinced as your fix implies there is some engine bug/problem memory management issue with Godot here.