diff --git a/cocos/3d/ui/components/sprite-component.ts b/cocos/3d/ui/components/sprite-component.ts index 6e6a0f56b5..5777890ac5 100644 --- a/cocos/3d/ui/components/sprite-component.ts +++ b/cocos/3d/ui/components/sprite-component.ts @@ -579,13 +579,13 @@ export class SpriteComponent extends UIRenderComponent { } } - // _onTextureLoaded() { - // if (!this.isValid) { - // return; - // } + private _onTextureLoaded () { + if (!this.isValid) { + return; + } - // this._applySpriteSize(); - // } + this._applySpriteSize(); + } private _applySpriteFrame (oldFrame: SpriteFrame | null) { // if (oldFrame && oldFrame.off) { @@ -601,11 +601,12 @@ export class SpriteComponent extends UIRenderComponent { if (spriteFrame) { if (!oldFrame || spriteFrame !== oldFrame) { // this._material.setProperty('mainTexture', spriteFrame); - this._activateMaterial(); + if (spriteFrame.loaded) { + this._onTextureLoaded(); + } else { + spriteFrame.once('load', this._onTextureLoaded, this); + } } - // else { - // this._applySpriteSize(); - // } } if (CC_EDITOR) { diff --git a/cocos/3d/ui/components/ui-model-component.ts b/cocos/3d/ui/components/ui-model-component.ts index 40767377c0..31f5f53379 100644 --- a/cocos/3d/ui/components/ui-model-component.ts +++ b/cocos/3d/ui/components/ui-model-component.ts @@ -52,14 +52,23 @@ export class UIModelComponent extends UIComponent { private _modelComponent: RenderableComponent | null = null; public onLoad () { - this._modelComponent = this.getComponent(cc.RenderableComponent) as RenderableComponent; - (this._modelComponent as any)._sceneGetter = cc.director.root.ui.getRenderSceneGetter(); + this._modelComponent = this.getComponent('cc.RenderableComponent') as RenderableComponent; + if (!this._modelComponent){ + console.warn(`Use this component on a node(${this.node && this.node.name}) that has a model component`); + return; + } + + this._modelComponent._sceneGetter = cc.director.root.ui.getRenderSceneGetter(); this._modelComponent.recreateModel(); } public onDestroy () { - this._modelComponent = this.getComponent(cc.RenderableComponent) as RenderableComponent; - (this._modelComponent as any)._sceneGetter = null; + this._modelComponent = this.getComponent('cc.RenderableComponent') as RenderableComponent; + if (!this._modelComponent){ + return; + } + + this._modelComponent._sceneGetter = null; this._modelComponent.recreateModel(); }