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

Godot 4.3 Windows导出C#脚本行为异常问题求助

Godot 4.3 C#地图生成器Windows导出后失效问题

用Godot 4.3 + C#开发了一款地图生成器,负责在地图上放置各类对象引用并检测位置可用性,采用标准Windows导出流程。编辑器内运行时仅存在计算延迟,但导出版本完全失效,生成逻辑无法正常执行。

导出与编辑器运行结果对比

导出版本运行结果

输出日志:
4 memorized asset 4 4 14 14 4 4 || spots 14 0 0 14 || assets on map 0 0 0 0

抛出异常:

ERROR: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'index')
at Godot.Collections.Array.GetVariantBorrowElementAt(Int32 index, godot_variant& elem)
at Godot.Collections.Array`1.get_Item(Int32 index)
at Godot.Node.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret)
at WorldBehaviour2.InvokeGodotClassMethod(godot_string_name& method, NativeVariantPtrArgs args, godot_variant& ret) 4
at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr godotObjectGCHandle, godot_string_name* method, godot_variant** arg)
at: void Godot.NativeInterop.ExceptionUtils.LogException(System.Exception) (:0)

编辑器预期运行结果

输出日志:
4 memorized asset 4 4 4 4 4 4 || spots 0 0 0 0 || assets on map 0 0 0 0
spots on map 31 dia [49, 74, 70, 51, 72, 66, 47, 73, 51, 81, 67, 52, 83, 46, 81, 46, 60, 69, 56, 69, 43, 63, 51, 57, 45, 52, 63, 58, 48, 45, 46]

可见导出版本中记忆项的列表槽位被错误分配,与编辑器行为完全不一致。

核心逻辑代码

所有列表均使用Godot.Collections.Array类型,核心逻辑如下:

public override void _Ready() {
    SetDefault();
    CallDeferred(nameof(DrawLargeMap));
}

// 启动生成逻辑
public void DrawLargeMap() {
    DrawCoverage(100); // 生成100个Vector3并加入列表
        
    // 遍历每个点位选择对象
    for (int i = 0 ; i < spots.Count ; i++) {
        SelectObj(context[i]);  // 从列表中选择对象
        // 遍历选中对象,设置地图上的属性
        for (int j = 0 ; j < selectedObj.Count ; j++) {
            SelectOnMap(i, selectedObj[j]); // 选择未在地图上绘制的对象
            // ... 其他逻辑
            SetOnMap(); // 将对象加入属性定义列表
        }
    }
}

所有方法均为带参数的基础void方法,无异步操作,逻辑需按特定顺序执行,无法拆分使用CallDeferred。

已尝试的解决方法

  • 降低计算开销
  • 将CallDeferred替换为直接调用DrawLargeMap
    以上方案均未解决问题,导出版本行为仍与编辑器不一致。

疑问

怀疑问题出在Godot.Collections.Array列表系统或.NET底层内存读取逻辑,考虑过使用线程但不熟悉用法。请问:

  1. Godot 4.3 Windows导出是否存在已知的C#相关问题?
  2. 打包成品时是否有安全/内存读取相关的调整要点?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 13:36:05