You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Godot 3.5中C#脚本无法实例化(程序集未加载)问题求助

解决Godot 3.5中“Cannot instance script because the project assembly is not loaded”报错

核心原因

你编写的DragAndDropController类没有继承Godot的节点基类,且_Input方法未正确重写引擎的虚方法,导致Godot无法识别并实例化这个脚本。

修正步骤

  1. 让类继承Godot节点类:将DragAndDropController继承自Node(或适合你场景的子类,比如Node2D),这是Godot脚本实例化的必要条件。
  2. 正确重写_Input方法:添加override关键字,因为_Input是Godot节点的虚方法,必须显式重写才能被引擎调用。

修正后的代码:

using Godot;
using System;

public class DragAndDropController : Node
{
    public override void _Input(InputEvent @event)
    {
        // Mouse in viewport coordinates.
        if (@event is InputEventMouseButton eventMouseButton)
            GD.Print("Mouse Click/Unclick at: ", eventMouseButton.Position);
        else if (@event is InputEventMouseMotion eventMouseMotion)
            GD.Print("Mouse Motion at: ", eventMouseMotion.Position);
    }
}

额外检查项

  • 确保脚本已正确附加到场景中的某个节点(比如Sprite或空Node),而非未关联任何节点。
  • 检查Godot编辑器的输出面板是否有隐藏的编译错误:虽然Visual Studio无报错,但Godot 3.5对.NET 7.0的兼容性不如.NET 6.0,建议切换到.NET 6.0 SDK尝试。
  • 确认脚本文件路径res://scripts/DragAndDropController.cs无拼写错误,文件存在于指定目录。

内容的提问来源于stack exchange,提问作者Ian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 09:42:54