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.

Question Why after using Animation.AddClip(). Length of added clips always = 1

Discussion in 'Scripting' started by Mariukh_Viacheslav, Apr 1, 2023.

  1. Mariukh_Viacheslav

    Mariukh_Viacheslav

    Joined:
    Jul 4, 2022
    Posts:
    3
    I am creating animationClip at runtime from json file, using KeyFrames and SetCurve.
    After creation, I want to split the created animationClip into several smaller clips:

    Code (CSharp):
    1. Animation anim;
    2. AnimationClip createdAnimationClip;
    3. anim.AddClip(createdAnimationClip,”name1”, 0, 100)
    4. anim.AddClip(createdAnimationClip,”name2”, 100, 200);
    5. anim.AddClip(createdAnimationClip,”name3”, 200, 500);
    everything goes except well,
    except one, all added clips in the anim clips array has length = 1 sec

    and when I try to play the animation, only the first second is played, although there are many more frames

    I can't figure out if this is a bug or am I doing something wrong.

    Unity version 2021.3.12
     
    Last edited: Apr 1, 2023
  2. Mariukh_Viacheslav

    Mariukh_Viacheslav

    Joined:
    Jul 4, 2022
    Posts:
    3
    if anyone comes across this problem. my solution was additionally set frameRate on each added clip:


    Code (CSharp):
    1. anim.AddClip(createdAnimationClip,”name1”, 0, 100);
    2.     anim[name1].frameRate = 24;//set your frameRate
    after that the length of the clip becomes correct.
     
    samana1407, Sluggy and Kurt-Dekker like this.