From 1be06343ece424e01eb6b27e3b56696b9a34998f Mon Sep 17 00:00:00 2001 From: min Date: Tue, 9 Jun 2026 20:41:09 +0300 Subject: [PATCH] =?UTF-8?q?fix(g20):=20=D0=BE=D1=82=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20setLabel=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20NPC=20=D0=B4=D0=BE=20npcSpawned-=D1=80=D0=B5=D0=B7=D0=BE?= =?UTF-8?q?=D0=BB=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit setLabel сразу после spawnNpc возвращал null от _resolveTweenTarget (маппинг localRef→realId ещё не записан). Метки молча терялись. Фикс: если ref начинается с npc_lua_ — откладываем через _npcCmd (re-вызов после npcSpawned). Иначе retry через 0.3с. --- src/editor/engine/GameRuntime.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/editor/engine/GameRuntime.js b/src/editor/engine/GameRuntime.js index fb01928..3027a93 100644 --- a/src/editor/engine/GameRuntime.js +++ b/src/editor/engine/GameRuntime.js @@ -3615,16 +3615,28 @@ export class GameRuntime { const ref = payload?.ref; const text = payload?.text; if (typeof ref !== 'string') return; - // ленивое создание менеджера меток if (!this.scene3d._labelManager) { this.scene3d._labelManager = new LabelManager(this.scene3d.scene); } const lm = this.scene3d._labelManager; - // резолвим меш объекта (примитив или модель) + const applyLabel = () => { + const tgt = this._resolveTweenTarget(ref); + const mesh = tgt && (tgt.data.mesh || tgt.data.rootMesh || tgt.data.rootNode); + if (mesh) { + lm.setLabel(ref, mesh, text, payload?.opts || {}); + } + }; + // Если NPC ещё не зарезолвлен — откладываем через _npcCmd + // (или просто несколько попыток с retry). const tgt = this._resolveTweenTarget(ref); - const mesh = tgt && (tgt.data.mesh || tgt.data.rootMesh || tgt.data.rootNode); - if (mesh) { - lm.setLabel(ref, mesh, text, payload?.opts || {}); + if (tgt) { + applyLabel(); + } else if (typeof ref === 'string' && ref.startsWith('npc_lua_')) { + // NPC ещё спавнится — откладываем + this._npcCmd(ref, () => applyLabel()); + } else { + // Retry через 0.3с (для primitive после sceneCreate) + setTimeout(applyLabel, 300); } } catch (e) { console.warn('[GameRuntime] scene.setLabel failed', e);