How to Set Tween Loop Type in Runtime?

Can anyone help me in changing a loop type of a Tween in runtime?

This is what I tried. I don’t understand what’s more that is needed.

//@input SceneObject TweenHolderObj;

         var tween = global.tweenManager.findTween(script.TweenHolderObj, "tweenName");
        global.tweenManager.setTweenLoopType(tween,2); //Want to set to PingPong 

So I figured out and solved it! Lol.

Solution Goes Like this.

var tweenScriptComponent = global.tweenManager.findTween(script.TweenHolderObj, "tweenName");
        for(var i=0; i< tweenScriptComponent.api.tween.length; i++){
            global.tweenManager.setTweenLoopType(tweenScriptComponent.api.tween[i], 2); 

Thanks for sharing the solution!

1 Like

Please note this solution will only work if it has multiple tweens, for single tween it will not go into for loop. In such case, use tweenComponent.api.tween

Also may have to tweak some parts inside the tweenType scripts to support fully runtime loop type change

Yes by multiple tweens Krunal means multiple objects that are recursively being affected by it. My case parent object was being alpha tweened with recursive checked and had two children objects. So if your solution is changing only one thing and not recursively use :
tweenScriptComponent.api.tween instead of a for loop approach because it’ll receive single object from findTween function.

If you are unsure about using for loop or if something doesn’t work try to debug using print(tweenScriptComponent.api.tween) in a line and check console log if you get multiple objects or single object and choose the approach accordingly

1 Like