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);