Search Unity

How to change an AnimationClip frameRate ?

Discussion in 'Editor & General Support' started by n0mad, Dec 4, 2009.

  1. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Hello,

    when you're creating AnimationClip() from scratch, its frameRate property is read-only.

    How are we supposed to change it ?
     
  2. giyomu

    giyomu

    Joined:
    Oct 6, 2008
    Posts:
    1,094
    changing clip speed instead won't be enough for your purpose ?
     
  3. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    It could not work in my scope, because I'm using clip speed dynamic changing during game, with a base reference of 1 in all of my code :roll:

    The other solution around would be to multiply every Keyframe.time by 2 (as this animationClip is duplicated from a FBX which frameRate is 30).

    But still, I'm surprised ... Why would this value be read-only, especially if we can create a new AnimationClip ? For performance reasons, people don't particularly want a fixed 60 fps ... :/
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
  5. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Unfortunately, I really make the speed variable dependant of something else than my script.

    I'm tuning it up or down to make it fit custom durations. Linking its dependancy to another clip would break everything.

    Anyway, why is it forbidden to change that frameRate value ?
    I can understand that at a clip level, it would mess other clips, but why wouldn't there be a Animation class level frameRate setter ?
     
  6. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Bump.

    If it is possible to edit that frameRate value when we create a new AnimationClip with the Editor menu, why would it be impossible if we create it by script ?
     
  7. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Good thing is you can easily adjust it through the above mentioned things.

    Just use a new speed value of frameRate / desiredFramerate

    or if you need to have it within a given duration, you can calculate that by using

    (frameRate * duration) / totalFrames


    as for the readonly: I would guess because you could never again refresh the asset if you altered an "unchangeable asset property" which is breaking the base idea behind automatic asset refreshment.

    If you create a new one you are setting up the base value for it again so you can later update it without breaking it (asset server, overwritting the clip, ...). For unity there is no difference if it is an animation editor clip or one from an fbx, its just a clip ...
     
  8. n0mad

    n0mad

    Joined:
    Jan 27, 2009
    Posts:
    3,732
    Ah thanks, those formulas will be useful for sure ^^

    As for the readability, I find it counter-productive, as we have to make tricks in order to just make it work. I mean, framerate is the core of 3D animation :/
    Imagine how a pain it would be for gamestudios that have strict rules to follow, like not changing framerate nor speed because the gamecode uses it, and it's have been written by another studio .. :roll:
    (not a rare scenario I guess)