Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

LeanTween: Any way to reuse/pool/delete tweens?

Discussion in 'Scripting' started by Reign_of_Light, Nov 12, 2014.

  1. Reign_of_Light

    Reign_of_Light

    Joined:
    Oct 15, 2014
    Posts:
    46
    Hi,

    I use LeanTween for tweening and I really love it. What I like the most about it (compared to other tweening engines I used in the past), is that you don't even have to instantiate tween-objects, you just pass what you want to tween as parameters to the LeanTween-class and everything is working fine. Unfortunately this seems to have a drawback as well. I hoped/expected that LeanTween would do some intelligent pooling in the background, or that it would at least delete tweens that have come to an end.
    I'm afraid I have been mistaken, since having a lot of entities doing a move-tween every few seconds, makes me run out of available tweens every time. (Error: "You have run out of available spaces for tweening. To avoid this error increase the number of spaces available for tweening when you initialize the LeanTween class. ex: LeanTween.init(800);")
    Of course I could do as suggested and increase "available spaces" (tween-count, I guess), but that doesn't look like a good, sustainable solution.
    Therefore I'd like to ask you, if there is any way of deleting finished tweens, or of pooling/reusing them, that you know of?
    Right now, I myself don't see any, as I can neither instantiate (and thereby reuse) tween-objects myself, nor do I find any method or parameter that makes LeanTween delete a tween.
     
    kikill likes this.
  2. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    I never used lean tween but in my own tweening soultuon I have Static tween methods on different tweening components that will either create the component on the object and tween, or it will use tweening components already on the game objects if present. Its a pretty trivial thing to implemenant if you got source code access.

    More or less just out a static method on the class that gets component and only creates a new one if it is null
     
  3. Reign_of_Light

    Reign_of_Light

    Joined:
    Oct 15, 2014
    Posts:
    46
    Thank you! Yes, modifying/extending on the lean-tween classes is an option of course. I just couldn't believe there is no built-in way to handle this, and my thought was that I must have overlooked something.

    There even is an 'setDestroyOnComplete(bool)' method, but unfortunately it does not only destroy the tween, but the tweened object as well, which is somewhat more than I asked for.
     
  4. dentedpixel

    dentedpixel

    Joined:
    Jul 15, 2012
    Posts:
    683
    Hey Reign!
    I am glad you are liking LeanTween. LeanTween does effectively destroy any tweens that have finished. It sounds like you must have a bunch of tweens around (over 400), that haven't finished. Unless you have discovered a bug that is keeping the tweens as being marked as finished...
     
    kikill likes this.
  5. mrekuc

    mrekuc

    Joined:
    Apr 17, 2009
    Posts:
    116
    I know this is a little old but I downloaded the latest scripts and all is working fine. I do have a lot of treest popping in but not all at once. It seems like tweens are not being resused. Any ideas? I bumped up the maxed allowed but still seems like it running out quickly.
     
  6. astechnolabs

    astechnolabs

    Joined:
    Jul 11, 2021
    Posts:
    20
    I had same issue, but I solved by putting my LeanTween content outside
    update
    function