fix: add missing 'origin' to built-in template entries - #26
Merged
moluopro merged 3 commits intoAug 7, 2026
Conversation
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).
There was a problem hiding this comment.
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 templateDictionaryentries 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 说明
修复:TypeScript 语言新建脚本时内置模板缺失 origin 字段导致的报错
问题描述
在编辑器中新建脚本并将 Script type 切换为 TypeScript 时,会触发如下错误:
根因分析
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_IN(core/object/script_language.h,值为 0),表示该模板为脚本语言自带的内置模板:影响范围
该问题仅影响编辑器 UI(新建脚本时的内置模板不可用),不影响运行时。修复改动为单行补全,无回归风险。