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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question LeanTween not consistency playing animation OnEnable

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

  1. NeilB133


    May 30, 2022
    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() {
    3.         startPosition = gameObject.GetComponent<RectTransform>().position;
    4.         ToPosition = startPosition.x - 0.1f;
    5.     }
    7.     void OnEnable() {
    8.         LeanTween.moveX(gameObject,ToPosition, 0.6f).setLoopPingPong().setIgnoreTimeScale(true);
    10.     }
    12.      private void OnDisable() {
    13.         LeanTween.reset();
    14.         gameObject.GetComponent<RectTransform>().position = startPosition;
    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


    May 30, 2022
    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.