Search Unity

Question LeanTween not consistency playing animation OnEnable

Discussion in 'UGUI & TextMesh Pro' started by NeilB133, Oct 15, 2022.

  1. NeilB133

    NeilB133

    Joined:
    May 30, 2022
    Posts:
    210
    So I've set up some 2 scripts. In one script it will control whether the Glove Pointer (GameObject) is active or inactive using the SetActive() method. In another script I will call logic in the OnEnable and OnDisable functions: Here is the script for this:

    Code (CSharp):
    1.     private void Start() {
    2.  
    3.         startPosition = gameObject.GetComponent<RectTransform>().position;
    4.         ToPosition = startPosition.x - 0.1f;
    5.     }
    6.  
    7.     void OnEnable() {
    8.         LeanTween.moveX(gameObject,ToPosition, 0.6f).setLoopPingPong().setIgnoreTimeScale(true);
    9.    
    10.     }
    11.  
    12.      private void OnDisable() {
    13.         LeanTween.reset();
    14.         gameObject.GetComponent<RectTransform>().position = startPosition;
    15.        
    16.     }
    In the video below, you'll see that even though one of the Glove Pointers is now active (it shows in the hierarchy as active and it's checked to say it's active) I need to manually check it again in order for the OnEnable code to execute. This doesn't appear to be the case with each Glove Pointer though, as some will fire the transition, but other's won't even though it's now active in the hierarchy. My question is then, how do I get each Glove Pointer to play the tween animation?

     
  2. NeilB133

    NeilB133

    Joined:
    May 30, 2022
    Posts:
    210
    Sacked that idea off as I just couldn't get it working when the state swapped between active and inactive, so now I've just instantiated a new Glove Pointer when the weapon is active, then destroy it when it isn't active anymore. Therefore in the code there is now just a one liner in the Start function.