Search Unity

LeanTween - A tweening engine that is up to 5x faster than competing engines!

Discussion in 'Assets and Asset Store' started by dentedpixel, Dec 3, 2012.

  1. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Code (CSharp):
    1. LeanTween.delayedCall(1.0f, () => Debug.Log("Test")).setIgnoreTimeScale(true);
     
    Only4gamers likes this.
  2. unity_7C40B2B07729C99A3F8B

    unity_7C40B2B07729C99A3F8B

    Joined:
    Jul 28, 2022
    Posts:
    2
    I've seen nice tutorials and they are recent. However, when I try to import (using asset store and package manager) LeanTween I get several errors and I can't use "LeanTween. ---" at all. Searching online I only found a forum of a user with similar errors and their answer was "LeanTween is too old, deprecated in 2018" but I can see it's not, it's still being used. So I have no idea why I get errors and I can't import the package properly. I was using DOTween but it is very complex for my limited knowledge, and all I want to do are position + alpha transitions, nothing crazy, but I can't find a simple way to do that with DOTween while LeanTween seems much easier for this! Any help? Thank you!
    PS: the errors I get are "Error while saving Prefab: 'Assets/LeanTween/Examples/Prefabs/EndlessPiece.prefab'." among several similar errors
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    What Unity Version are you using and what LeanTween version are you using? You can try to just delete the Examples folder, if the errors only come from there.
     
    tvemn likes this.
  4. unity_7C40B2B07729C99A3F8B

    unity_7C40B2B07729C99A3F8B

    Joined:
    Jul 28, 2022
    Posts:
    2
    I just had to move LeanTween.cs to the Plugins folder for some reason that I can't understand. Also, my scripts that need to use LeanTween must be in the root folder of the project, if I move the script to any folder, the LeanTween call doesn't work anymore. I'm new to coding and Unity so I don't understand anything. But since it's working this way, I'll keep going
     
  5. clonedd1x

    clonedd1x

    Joined:
    Jun 17, 2022
    Posts:
    1
    Hello, currently I have a bar that is run on time. Is there anyway to decrease the current time. Im thinking something like this. Is there any function etc?

    SetTime(GetTime - 30)

    If anyone could respond it would mean alot
     
  6. yuliyF

    yuliyF

    Joined:
    Nov 15, 2012
    Posts:
    197
    Does anyone to do a speed tests LeanTween vs DoTween - ? I have a doubt.. proofs, proofs give me a proofs
     
  7. Dark_Seth

    Dark_Seth

    Joined:
    May 28, 2014
    Posts:
    140
    HI All.

    Just installed LeanTween and Getting these errors.

    Any help would be great!

    upload_2022-9-5_16-31-30.png
     
  8. Dark_Seth

    Dark_Seth

    Joined:
    May 28, 2014
    Posts:
    140
    BTW as soon as I remove Cinimachine everthing works. So can't use this
     
  9. dansav

    dansav

    Joined:
    Sep 22, 2005
    Posts:
    510
  10. nivrefilm

    nivrefilm

    Joined:
    Jan 30, 2021
    Posts:
    3
    tvemn likes this.
  11. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    Ah, right. I added a gh-pages site rendering the documentation content. The HTML was not built to be used outside the dentedpixel site, but this gives back basic functionality to browse the docs:
    https://johannesdeml.github.io/LeanTween/classes/LTSpline.html#api-classes

    Note: I have no intention of maintaining the project, I just thought this would be a nice addition, since it was a low hanging fruit.
     
  12. Dark_Seth

    Dark_Seth

    Joined:
    May 28, 2014
    Posts:
    140
    Anybody manage to use this with Cinemachine?
     
  13. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    How can I play a sound (call a function) every time a repeating tween repeats? I have a tween that repeats continuously (setLoopPingPong(-1)), and I need to play a sound every time it starts (or ends). SetOnComplete does nothing if PingPong is set to a positive number, and SetOnStart doesn't seem to work at all (the sample code gives me an error). Is this possible?
     
    Last edited: Jan 11, 2023
  14. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    700
    Maybe not use LoopPingPong and instead play the tween again on SetOnComplete? Or just use a coroutine instead.
     
  15. ObsidianSpire

    ObsidianSpire

    Joined:
    Sep 13, 2013
    Posts:
    48
    Hi, I'm attempting to use LeanTween and I was wondering what the best way to make a group of objects follow behind a jumping target would be? Think Yoshi's Island on the Super Nintendo where the eggs/objects follow Yoshi in their jump path until each egg reaches a spot close enough to stop.

    https://forum.unity.com/threads/dotween-hotween-v2-a-unity-tween-engine.260692/page-62#post-4492342

    That post from a couple years ago in another thread mentions following a moving target, but the sample code I tried from the documentation doesn't work quite like I'd hoped. I was hoping for more of an accurate arc/parabola.

    Code (CSharp):
    1. LTDescr d = LeanTween.followLinear(this.transform, playerController.midPointOfPlayer, LeanProp.position, fMoveSpeedForDoubleJumpFollow);
    2.         //d.setTime(fDur);
    3.         //d.setOnComplete(aResetFromMAXDJ);
    4.         Invoke("ResetCatFromMaxDJ", fDur);
    I already store the position of the target/player along their jump arc in the player's class, but I'm intending to start the following gameObjects on their own arcs before the player is guaranteed to land because it would look weird if they had to wait for the player that much. I saw the "move along a path" function included in the plugin, which looks like it might work, but I think I'd need to update the following object's tween path as new positions for the player's jump arc get stored.

    Is that the right idea and even possible or is something else a better approach?
     
  16. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    Just to remind myself on the solution I've found, and anybody else that might be interested:

    Code (CSharp):
    1. tC = theObj.GetComponent<TextMeshProUGUI>().color;
    2. LeanTween.value(theObj, a =>  theObj.GetComponent<TextMeshProUGUI>().color = new Color(tC.r, tC.g, tC.b, a), 0.1f, 1f, 1f);
     
  17. John-B

    John-B

    Joined:
    Nov 14, 2009
    Posts:
    1,262
    How can I tell if a sequence is running? LTSeq.isTweening doesn't work. I can look at tweensRunning, but that won't work if other tweens are running in addition to the sequence.
     
  18. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    Hello,
    I have a problem with a simple LeanTween.value() method. I tried to use it to tween material float value. It works fine until I make any kind of change in the editor(not even related to the script) and tween just stops working. It starts to work again when I make and save any change in code editor (basically to recompile scripts). Not sure what causes the problem. Code looks like this:

    Code (CSharp):
    1. LeanTween.value(gameObject, SetFlashAmount, 0f, 1f, FLASH_DURATION);
    2.  
    3. private void SetFlashAmount(float _amount)
    4.     {
    5.         flashMaterial.SetFloat(FLASH_AMOUNT_PARAMETER, _amount);
    6.     }
    Before in value() method I did not write game object. The behavior was the same, except that it threw null exception in editor. But it should not effect the situation because even documentation says adding gameObject is optional and is mostly for tracking tween.
    Please help me, I am on a verge of switching to DOTween or writing my own tweens :D
     
  19. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    LeanTween.value() will tween the material's value when your app is running and you execute that code. If the material is also changing outside of when the app and this code is running (like when you change other things in the editor and cause a recompile) then something else is modifying the material too.

    Some shaders modify their properties based on the timescale of the editor/app. This is common for many shader effects that happen over time. Is it possible your material's shader is updating the FLASH_AMOUNT_PARAMETER in such a way?

    You said "It works fine until I make any kind of change in the editor(not even related to the script)" which makes me think the shader is also trying to change this parameter based on the editor's time.

    Otherwise it looks like you are using this leantween function correctly.
     
  20. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    I apply changes (in editor and code) not in play mode but the problem occurs exactly after making any kind of change in editor(not in play mode). And as I mentioned earlier, I tried to remove logic with material and it still happens with only float value. FLASH_AMOUNT_PARAMETER is a constant so it should not change.
     
  21. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    I meant the value of whatever the Flash Amount parameter is pointing at (in the shader) may be changing in the shader based on a time. From what I can tell, what seems to be happening is multiple things are modifying the material or shader's value.

    Are multiple gameObjects sharing this material and trying to modify it? That could also be an issue. Are you making instance copies of the material for every gameObject using it, or are you using the sharedMaterial on all of them? How are you assigning flashMaterial?

    Can you share more of the code structure around what is calling the code below? Is this on a script on multiple gameObjects?
    1. LeanTween.value(gameObject, SetFlashAmount, 0f, 1f, FLASH_DURATION);
     
  22. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    Multiple objects have this material and they try to change parameter on hit (onTriggerEnter). I just made material out of shader and assigned it under sprite renderer of each object in inspector. Scripts get material reference from sprite renderer:

    Code (CSharp):
    1.  
    2. spriteRenderer = GetComponent<SpriteRenderer>();
    3. flashMaterial = spriteRenderer.material;
    4.  

    Tween is inside a method that is being called OnTriggerEnter (or Stay):

    Code (CSharp):
    1. protected virtual void OnTriggerStay2D(Collider2D _other)
    2.     {
    3.         if (damageOnContact && (playerLayer & (1 << _other.gameObject.layer)) > 0)
    4.         {
    5.             PlayerHealth _player = _other.GetComponent<IDamagable>() as PlayerHealth;
    6.             if (_player != null)
    7.             {
    8.                 _player.GetHurt(damagePerHit);
    9.             }
    10.         }
    11.     }
     
  23. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    Enemy variation is called when raycast from player attack hits so the code is similar
     
  24. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    In meantime I managed to do what I needed with DOTween so the problem is kind of solved but it still would be interesting to know what went wrong with leantween solution
     
  25. Velvety

    Velvety

    Joined:
    May 4, 2009
    Posts:
    153
    Ok, that makes sense. If you call the following code for each gameObject, it will create an instance (copy) of the material for that gameObject.
    1. flashMaterial = spriteRenderer.material;
    That means those gameObjects have a copy of the material that you are modifying at runtime while the app is running. Once you press stop, those instances disappear. So when you say the material is changing when you make other changes in the editor, remember that you aren't modifying the original material with your code, you are modifying copies of it at runtime.

    Also, (and this may be a separate problem) if you are calling LeanTween.value(gameObject, SetFlashAmount, 0f, 1f, FLASH_DURATION) from OnTriggerStay(), that will start a new tween every frame and cause a bunch of unwanted tweens fighting over setting the value. It looks like you are doing damage every frame, is that the intention? If so, you probably don't want to also start a tween on the material each frame because you will have multiple tweens interfering with each other trying to set the same value differently.
     
  26. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    The error is triggered by editing something NOT in runtime and I understand what you are trying to say but issue is still somewhere else. I use eyeframes (cooldown between damage can be triggered) in onTriggerStay so there should be no problems there.
    I will probably stick with dotween solution because it already works but thank you for help. I can finally get some rest after multiple hour fight with leantween :D
     
  27. arweedas

    arweedas

    Joined:
    Jul 3, 2021
    Posts:
    7
    Maybe I just poorly communicated the issue because English is not my native language and it is quite hard to explain what is actually happening in my editor.