Skip to content

Calling killTweensOf or killAll inside a tween on complete callback throws Uncaught TypeError: cannot read properties of null #7003

@Stever1388

Description

@Stever1388

Version

  • Phaser Version: 3.87.0
  • Operating system: Windows
  • Browser: Chrome

Description

Calling this.tweens.killTweensOf or this.tweens.killAll() inside the onComplete callback of a tween, but only if that callback was added using myTween.on/once(Phaser.Tweens.Events.TWEEN_COMPLETE, mycallback), throws an null reference exception.

Example Test Code

export default class TweeCompleteIssue extends Phaser.Scene {

  create() {
    const i = this.add.rectangle(500,500,100,100,0xff0000);

    // doing it this way doesn't cause the error
    // this.add.tween({ targets: i, duration: 1000, props: { scale: 0.5 }, onComplete: () => this.tweens.killTweensOf(i) });

    // doing it this way does cause the error
    // this.add.tween({ targets: i, duration: 1000, props: { alpha: 0.5 } }).once(Phaser.Tweens.Events.TWEEN_COMPLETE, () => this.tweens.killTweensOf(i));
    this.add.tween({ targets: i, duration: 1000, props: { alpha: 0.5 } }).once(Phaser.Tweens.Events.TWEEN_COMPLETE, () => this.tweens.killAll());
  }
}

Additional Information

Uncaught TypeError: Cannot read properties of null (reading 'onComplete')
    at Tween.dispatchEvent (phaser.js:241091:1)
    at Tween.onCompleteHandler (phaser.js:239011:1)
    at Tween.onCompleteHandler (phaser.js:240722:1)
    at Tween.nextState (phaser.js:240702:1)
    at Tween.update (phaser.js:241014:1)
    at TweenManager.step (phaser.js:236256:1)
    at TweenManager.update (phaser.js:236215:1)
    at EventEmitter.emit (phaser.js:220:1)
    at Systems.step (phaser.js:200464:1)
    at SceneManager.update (phaser.js:197703:1)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions