Search Unity

Question Why is the animation duration different?

Discussion in 'Animation' started by Pytchoun, Jan 21, 2023.

  1. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203


    Why does he tell me that the length is 3.3 at the top when obviously it's only 3.17? For any animation the 2 lengths never match.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,565
    It's not
    3.17
    , it's
    3:17
    which is based on the animation's frame rate. Scrub through the timeline and see what the last two digits are when the first changes from 2 to 3.

    Why doesn't it just use seconds? I have no idea, animators have weird conventions.
     
    mandisaw likes this.
  3. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Code (CSharp):
    1. public IEnumerator Reload()
    2.     {
    3.         if (!IsReloading && _currentAmmo != _weaponSO.MaxAmmo)
    4.         {
    5.             IsReloading = true;
    6.             OnReload?.Invoke(this, EventArgs.Empty);
    7.  
    8.             _audioSource.clip = _weaponSO.ReloadClip;
    9.             _audioSource.pitch = Random.Range(1.4f, 1.8f);
    10.             _audioSource.Play();
    11.  
    12.             // Wait for the end of the reload animation
    13.             yield return new WaitForSeconds(_weaponSO.ReloadAnimationClip.length - 0.13f);
    14.  
    15.             _currentAmmo = _weaponSO.MaxAmmo;
    16.             IsReloading = false;
    17.  
    18.             OnAmmoUpdate?.Invoke(this, new OnAmmoUpdateEventArgs
    19.             {
    20.                 CurrentAmmo = _currentAmmo,
    21.                 MaxAmmo = _weaponSO.MaxAmmo
    22.             });
    23.         }
    24.     }
    Here is my code and for me the animation is already finished that he don't go next, that why i have to add a minus.That why i think animation length is wrong. What can i do ?

    What do you mean by 'changes from 2 to 3' ?
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,565
    That code should work without the
    -0.13
    . Most likely the reload animation isn't yet playing when the coroutine starts so they're out of sync. That can probably be solved by yielding until the correct animation starts, though you still run the risk of it not starting or getting interrupted while you wait. Otherwise, you'd have to use a different animation system which provides a proper way to wait for animations to finish.
     
    Last edited: Jan 22, 2023
  5. Pytchoun

    Pytchoun

    Joined:
    Apr 12, 2015
    Posts:
    203
    Like what ?
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,565
    I can't actually tell you about it because advertising isn't allowed here (except in signatures).