diff --git a/cocos/spine/skeleton.ts b/cocos/spine/skeleton.ts index 79ebe5769db..f3204a22f71 100644 --- a/cocos/spine/skeleton.ts +++ b/cocos/spine/skeleton.ts @@ -312,6 +312,8 @@ export class Skeleton extends UIRenderer { private _slotTextures: Map | null = null; + private _customMaterialInstance: MaterialInstance | null = null; + _vLength = 0; _vBuffer: Uint8Array | null = null; _iLength = 0; @@ -636,6 +638,21 @@ export class Skeleton extends UIRenderer { this.markForUpdateRenderData(); } + get customMaterialInstance (): MaterialInstance | null { + if (!this._customMaterial) { + return null; + } + if (!this._customMaterialInstance) { + const matInfo = { + parent: this._customMaterial, + subModelIdx: 0, + owner: this, + }; + this._customMaterialInstance = new MaterialInstance(matInfo); + } + return this._customMaterialInstance; + } + public __preload (): void { super.__preload(); if (EDITOR_NOT_IN_PREVIEW) { @@ -1208,14 +1225,17 @@ export class Skeleton extends UIRenderer { if (inst) { return inst; } - - const material = this.getMaterialTemplate(); - const matInfo = { - parent: material, - subModelIdx: 0, - owner: this, - }; - inst = new MaterialInstance(matInfo); + if (this._customMaterialInstance) { + inst = this._customMaterialInstance; + } else { + const material = this.getMaterialTemplate(); + const matInfo = { + parent: material, + subModelIdx: 0, + owner: this, + }; + inst = new MaterialInstance(matInfo); + } this._materialCache[key] = inst; inst.overridePipelineStates({ blendState: {