godotengine / godot

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

"Cannot instance script because the associated class could not be found." error when loading C# assembly + .pck #76074

Closed zkWildfire closed 1 year ago

zkWildfire commented 1 year ago

Godot version

4.0.2.stable.mono.official [7a0977ce2]

System information

Windows 10 21H2

Issue description

I'm trying to implement modding support in a game I'm working on, but scenes from my test mod are unable to be loaded correctly. When I load a scene, the scene loads but Godot fails to create the script attached to the scene and prints the following error:

E 0:00:00:0724   Godot.NativeInterop.NativeFuncs.generated.cs:332 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr , IntPtr , System.Void** , System.Void* ): Cannot instance script because the associated class could not be found. Script: 'res://Foo.cs'. Make sure the script exists and contains a class definition with a name that matches the filename of the script exactly (it's case-sensitive).
  <C++ Error>    Method/function failed. Returning: false
  <C++ Source>   modules/mono/csharp_script.cpp:2301 @ can_instantiate()
  <Stack Trace>  Godot.NativeInterop.NativeFuncs.generated.cs:332 @ void Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr , IntPtr , System.Void** , System.Void* )
                 NativeCalls.cs:3435 @ Godot.GodotObject Godot.NativeCalls.godot_icall_1_371(IntPtr , IntPtr , Int32 )
                 PackedScene.cs:126 @ Godot.Node Godot.PackedScene.Instantiate(Godot.PackedScene+GenEditState )
                 Game.cs:77 @ void Game._Process(Double )
                 Node.cs:1795 @ Boolean Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 CanvasItem.cs:1371 @ Boolean Godot.CanvasItem.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 Node2D.cs:516 @ Boolean Godot.Node2D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 Game_ScriptMethods.generated.cs:31 @ Boolean Game.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
                 CSharpInstanceBridge.cs:24 @ Godot.NativeInterop.godot_bool Godot.Bridge.CSharpInstanceBridge.Call(IntPtr , Godot.NativeInterop.godot_string_name* , Godot.NativeInterop.godot_variant** , Int32 , Godot.NativeInterop.godot_variant_call_error* , Godot.NativeInterop.godot_variant* )

I was able to replicate this behavior in an MCVE, linked below (and where the above error message is from).

Steps for reproducing the issue can be found in the MCVE repo's readme. I've verified that I can clone the repository, follow those steps, and repro the issue. I can repro the issue in my game on both Windows (Win10 21H2) and Linux (Ubuntu 22.04), and on Windows (Win10 21H2) with the MCVE. I did not test the MCVE project on Linux.

There are a few GitHub issues that are related:

Steps to reproduce

Steps to reproduce the issue can be found in this repository's README: https://github.com/MYTX-Wildfire/godot-pck-mcve

Minimal reproduction project

mcve.zip

Calinou commented 1 year ago

Thanks for the report. This was already reported in https://github.com/godotengine/godot/issues/75352, so closing to consolidate the issue tracking there.

diybl commented 1 year ago

are there any play to fix this bug?? now has publish 4.02 version

but this bug is very serious for .net developers.