Skip to content

fix: add missing 'origin' to built-in template entries - #26

Merged
moluopro merged 3 commits into
godothub:mainfrom
feSHt377:fix/builtin-template-missing-origin
Aug 7, 2026
Merged

fix: add missing 'origin' to built-in template entries#26
moluopro merged 3 commits into
godothub:mainfrom
feSHt377:fix/builtin-template-missing-origin

Conversation

@feSHt377

@feSHt377 feSHt377 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR 说明

修复:TypeScript 语言新建脚本时内置模板缺失 origin 字段导致的报错

问题描述

在编辑器中新建脚本并将 Script type 切换为 TypeScript 时,会触发如下错误:

ERROR: ./core/object/script_language_extension.h:295 - Condition "!d.has("origin")" is true. Continuing.

根因分析

Godot 引擎在 ScriptLanguageExtension::get_built_in_templates()core/object/script_language_extension.h)中会将脚本语言扩展返回的模板字典解析为内部的 ScriptTemplate,并对每个字段做硬性校验(ERR_CONTINUE)。其中第 295 行校验 origin 键,缺失该键的模板会被直接跳过并打印上述错误。

Gode 的 TypeScriptLanguage::_get_built_in_templates() 通过辅助函数 make_template_entry()src/script/typescript_language.cpp:144)构造模板字典,仅填写了 inherit / name / description / content / id 五个键,遗漏了 origin。因此在新建脚本对话框中切换 Script type 为 TypeScript 时,引擎解析到缺失 origin 的字典即触发校验失败,两个内置模板(Default / Tool)被全部丢弃,模板下拉列表为空。

修复方案

按 Godot 的约定为模板字典补上 origin 字段,取值 TemplateLocation::TEMPLATE_BUILT_INcore/object/script_language.h,值为 0),表示该模板为脚本语言自带的内置模板:

entry["origin"] = 0; // TEMPLATE_BUILT_IN

影响范围

该问题仅影响编辑器 UI(新建脚本时的内置模板不可用),不影响运行时。修复改动为单行补全,无回归风险。

TypeScriptLanguage::_get_built_in_templates returns template dicts built
by make_template_entry, which omitted the 'origin' key. Godot's
ScriptLanguageExtension::get_built_in_templates requires it and skips any
entry without it. Selecting TypeScript in the New Script dialog therefore
produced the '!d.has(origin)' error and dropped all templates.
Set origin to TEMPLATE_BUILT_IN (0).
Copilot AI lite review requested due to automatic review settings August 7, 2026 09:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Godot 4.7 integration issue where the TypeScript script language’s built-in template dictionaries were being rejected by the engine due to a missing required "origin" field.

Changes:

  • Add the missing "origin" key to the built-in template Dictionary entries returned to Godot.
  • Ensure the engine’s strict template parsing no longer drops the “Default” and “Tool” templates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/script/typescript_language.cpp Outdated
@moluopro
moluopro merged commit 9de3df2 into godothub:main Aug 7, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants