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

Tween.remove() causes error "Cannot read properties of null (reading 'remove')" #6539

Closed
orcomarcio opened this issue Jul 6, 2023 · 3 comments

Comments

@orcomarcio
Copy link

Version

  • Phaser Version: 3.60
  • Operating system: Windows 11
  • Browser: Chrome

Description

Launching .remove() on a tween causesthe following error:
Uncaught TypeError: Cannot read properties of null (reading 'remove')

This call used to work on the previous patch.

Additional Information

image

@photonstorm
Copy link
Collaborator

How are you removing it? Because this works fine:

        const van = this.add.image(100, 100, 'van');

        const tween = this.tweens.add({
            targets: van,
            x: 700,
            y: 500,
            duration: 2000,
            loop: 4
        });

        this.input.on('pointerdown', () => {
            tween.remove();
        });

@orcomarcio
Copy link
Author

orcomarcio commented Jul 7, 2023

Sorry, I purposefully didn't add the code example because the whole process is spread across my framework and there wasn't a easy way to put it here concisely.

I'm gonna investigate further. I wonder if in the old patch tweens weren't automatically removed when they finished, so removing it after the fact didn't give error. The weird thing is that if i put stop() instead of remove() it doesn't give an error, and reading the comments on these function i think stop() is the cleanest way to remove a tween anyway.

@photonstorm
Copy link
Collaborator

In 3.60 (Final) Tweens are automatically cleaned-up and destroyed by the Tween Manager. If you need to do this early, you can call stop on them to create the same result. Doing this after the Tween is already destroyed will cause an error. If you don't want this feature and need your Tween to be long-lived and fully under your control, you can add the persists: true parameter to the tween config. It's then up to you when you nuke it (handy for stuff like tweens linked to UI events).

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