How to do a killTweensOf() like with Gsap but with Tween.js

I’m investigating some way to kill a tween currently running , Let’s say a cube doing a translation.
In the idea I would like to replicate the behaviour of the killTweensOf() of the Gsap tool.

Is that possible in a way or another?


Hi @glitchbutcher,

I am not sure if there is a global method in tween.js to kill all active tweens. But you can easily do so yourself by keeping a list of all tweens you’ve started.

Then you just execute stop() on each reference and the tweens will stop.

var tween = entity.tween(fromProperty).to(toProperty, duration, easing);

// sometime later

Ah yes good point.
Well a bit more lines of code but then , sounds good :slight_smile:
Tween.stop(); does this free up the cache?
I mean , is it still “there” or is it properly killing the tween and “free up” memory usage as per the Gsap KillTweenof()?

Checking the playcanvas tween.js source code yes, as soon as a tween stops it will be automatically removed from the list of active tweens. So the Javascript garbage collector will automatically free that memory as long as you don’t keep any reference to that tween in your code.

So after you stop the tween, make sure to set that reference to undefined if it’s an object property or remove it from any of your lists. For example:

this.myTween = undefined;

Thanks !