fix(unreal): guard TS blueprint gen against missing GeneratedClass - #2355
Open
ZhiruiLi wants to merge 1 commit into
Open
fix(unreal): guard TS blueprint gen against missing GeneratedClass#2355ZhiruiLi wants to merge 1 commit into
ZhiruiLi wants to merge 1 commit into
Conversation
LoadOrCreate used to succeed when a stale .uasset lost its parent class, leaving GeneratedClass null; CodeAnalyze then called AddFunction and crashed the editor. Bail out safely, recreate under a live TS parent when possible, and check LoadOrCreate return values on the JS side.
ZhiruiLi
force-pushed
the
fix/unreal-ts-blueprint-null-generated-class
branch
from
August 5, 2026 10:27
22832a5 to
baa27bc
Compare
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.
修复编辑器在生成 TypeScript 蓝图时,因
GeneratedClass为空而在UPEBlueprintAsset::AddFunction中空指针崩溃的问题。当磁盘上已有陈旧的 TS 蓝图资产,且其记录的父类已无法加载时,
LoadOrCreate仍会“成功”返回,随后CodeAnalyze继续调用AddFunctionWithMetaData,最终在GeneratedClass->GetSuperClass()处以访问违例崩溃(读地址形如0x38,对应UStruct::SuperStruct偏移)。问题描述
CodeAnalyze在编辑器启动或 TypeScript 源码变更时,会为继承 UE Native 类型的 TS 类生成/更新蓝图资产,流程大致为:LoadOrCreateWithMetaData(...)AddFunctionWithMetaData/AddMemberVariableWithMetaDataSave()→ 编译并写回.uasset典型复现链:
.uasset记录的父类加载失败,TypeScriptGeneratedClass与其父类 “both will fail to load”根因不是随机内存破坏,而是空指针未保护:
.uasset记录的父类(例如已被删除或重命名的 Native 类)加载失败Blueprint可能半载成功,但GeneratedClass为空LoadOrCreate仍return trueAddFunctionWithMetaDataGeneratedClass->GetSuperClass()对空指针解引用并崩溃同一文件中,
Save/RemoveNotExisted*已有空指针判断,而AddFunction/AddMemberVariable/SetupAttachment*等生成路径缺少入口防护。此外,即便勉强避免崩溃,用户把 TS 基类改到一个仍然有效的父类后,也会被坏掉的旧资产卡住,无法自动恢复。
解决方案
1. C++:
UPEBlueprintAsset入口防护IsAssetReady():在Blueprint/GeneratedClass无效时打错误日志并早退AddFunction/AddFunctionWithMetaData/AddMemberVariable*/SetupAttachments等调用点统一检查AddFunction中对SuperClass做空判断CanChangeCheck*宏改用GetNameSafe(GeneratedClass),避免保护逻辑自身二次崩溃2. C++:
LoadOrCreate正确处理坏资产GeneratedClass无效时不再假装成功ParentClass(TS 已换到仍然可加载的基类):.uassetGeneratedClass继续这样既避免编辑器崩溃,也保留“修改 TS 基类即可恢复”的工作流,无需手动删除坏资产。
3. C++:
Save()编译后刷新缓存CompileBlueprint可能 reinstance 类,旧UClass会被标记为无效。编译后重新从
Blueprint->GeneratedClass刷新缓存指针,避免把失效类继续当作派生 TS 类的父类往下传。4. JS/TS:
CodeAnalyze检查返回值getUClassOfType中LoadOrCreate失败或GeneratedClass为空时跳过,不再把它当作基类使用onBlueprintTypeAddOrChange中LoadOrCreateWithMetaData失败时直接 return,不再继续AddFunction同步修改了源码与运行时产物:
PuertsEditor/CodeAnalyze.tsContent/JavaScript/PuertsEditor/CodeAnalyze.js修改文件
unreal/Puerts/Source/PuertsEditor/Public/PEBlueprintAsset.hunreal/Puerts/Source/PuertsEditor/Private/PEBlueprintAsset.cppunreal/Puerts/PuertsEditor/CodeAnalyze.tsunreal/Puerts/Content/JavaScript/PuertsEditor/CodeAnalyze.js兼容性说明
MarkAsGarbage/MarkPendingKill按 UE5 / UE4 分支处理