-
-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Open
Labels
Description
Godot version
v4.0.1.stable.mono.official [cacf499]
System information
Windows 10
Issue description
Exporting a script from one godot project and loading it in another does not work (following https://docs.godotengine.org/en/stable/tutorials/export/exporting_pcks.html). The ResourceLoader.Load<Script>() call finds the script and succeeds, but when assigning the script to a node, the following error occurs:
E 0:00:00:0477 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://HelloWorld.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:5208 @ void Godot.NativeCalls.godot_icall_1_583(IntPtr , IntPtr , Godot.Variant )
GodotObject.cs:434 @ void Godot.GodotObject.SetScript(Godot.Variant )
ImportScript.cs:24 @ void ImportScript._Ready()
Node.cs:1783 @ Boolean Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
Node3D.cs:988 @ Boolean Godot.Node3D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name& , Godot.NativeInterop.NativeVariantPtrArgs , Godot.NativeInterop.godot_variant& )
ImportScript_ScriptMethods.generated.cs:24 @ Boolean ImportScript.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* )
Loading other resources (e.g. scenes) works. The assembly was also loaded successfully. Might be related to this reported issue: .NET 6 - Running exported PCK fails to load scripts or fails to load hostfxr #72159
Steps to reproduce
Note: With the minimal reproduction project, only steps 3-5 and step 8 are required.
- Create two new Godot Projects (an exporting and an importing project)
- In the exporting, create a new script "HelloWorld" in res:// that prints "Hello World" on _Ready
- Export the exporting project (with "Runnable" unchecked) into a .pck file for your platform
- Copy the exported .pck file and the project's .dll from
.godot\mono\temp\bin\ExportRelease\win-x64 - Paste the two files to the res:// folder of the importing project
- In the importing project, create a 3D scene and add a new script to the root node
- In the new script, paste the _Ready function below
- Run the importing project and check the Debugger->Errors list
public override void _Ready()
{
// Prepare empty node
Node3D node = new Node3D();
AddChild(node);
// Load assembly and pck file
System.Reflection.Assembly.LoadFile(ProjectSettings.GlobalizePath("res://ExportingProject.dll"));
ProjectSettings.LoadResourcePack("res://ExportingProject.pck");
// Load script and assign it
Script script = ResourceLoader.Load<Script>("res://HelloWorld.cs");
node.SetScript(script);
}Minimal reproduction project
lonevox, preslavnpetrov, yuna0x0, OmnesPotens, vonweller and 4 more