Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Stever1388 opened this issue Jan 9, 2025 · 0 comments

Comments

@Stever1388
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants