TypeError: Cannot read properties of null (reading ‘height’)
at ReelItemAni.MakePixelPerfect (ReelItemAni.ts:141:110)
at ReelItemAni.update (ReelItemAni.ts:45:37)
at component-scheduler.ts:281:35
at ReusableInvoker._invoke (component-scheduler.ts:233:13)
at ReusableInvoker.invoke (component-scheduler.ts:195:14)
at ComponentScheduler.updatePhase (component-scheduler.ts:480:28)
at Director.tick (director.ts:746:37)
at callback (game.ts:734:26)
After i run the program this error appears. The “height” property is “null” in this method:
public MakePixelPerfect(){
this.sprite.sizeMode = 0;
this.sprite.node.getComponent(UITransform).width = this.nWidth;
this.sprite.node.getComponent(UITransform).height = Math.floor(this.nWidth * this.sprite.spriteFrame.height / this.sprite.spriteFrame.width);
}
I don’t know why. Please help me. Thanks!