From 12aedf1491cfaa408254d4f8a55367cf19f93e53 Mon Sep 17 00:00:00 2001 From: dgflash Date: Wed, 29 Apr 2026 22:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/module/common/CCEntity.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/assets/module/common/CCEntity.ts b/assets/module/common/CCEntity.ts index 4124923..48ac456 100644 --- a/assets/module/common/CCEntity.ts +++ b/assets/module/common/CCEntity.ts @@ -93,7 +93,7 @@ export abstract class CCEntity extends ecs.Entity { path = (ctor as any).GAME_PREFAB_PATH; bundleName = (ctor as any).GAME_PREFAB_BUNDLE; if (path == null) { - throw new Error(`组件 ${(ctor as any).name} 未使用 @game.prefab 装饰器注册,请添加 @game.prefab('path/to/prefab') 装饰器或手动传入路径参数`); + throw new Error(`组件 ${(ctor as any).name} 未使用 @prefab.register 装饰器注册,请添加 @prefab.register('path/to/prefab') 装饰器或手动传入路径参数`); } } @@ -101,10 +101,13 @@ export abstract class CCEntity extends ecs.Entity { // 跟随父节点释放自动释放当前资源 if (parent instanceof GameComponent) { - node = await parent.createPrefabNode(path, bundleName); + const result = await parent.createPrefabNode(path, bundleName); + if (result == null) return null; + + node = result; // 检查实体是否已销毁 - if (!this.isValid) { + if ( !this.isValid) { console.warn('[OopsFramework]', `实体已销毁,取消添加预制体组件: ${(ctor as any).name}`); node.destroy(); return null;