- Home /
Why can't I animate an int or enum?
Is there a way to animate ints or enums? (with mecanim)
Answer by SilentSin · Jan 24, 2015 at 03:54 AM
I don't think so. Only floats.
You'd have to animate a float and cast it to an int or enum everywhere you use it.
cheers, using a struct of bools. any idea why no int recording support?
If I were to guess, I would assume it's a purely logic-driven decision.
Let's say your game is running at 10 frames per second. You're scaling a value from 0 to 1,000 in one second. That means that every frame, the number grows by 100. But what if your game's running at 10,000 frames per second? Or even 1,005 frames per second. Integers are truncated, so any amount less than 1 per frame would round down to 0.
Additionally, Let's say you're running at 10 frames per second and are scaling from 0 to 970 ins$$anonymous$$d. That's 9.7 per frame, or 9 rounded down. You would logically only reach 900 after one second has elapsed.
Because of this, it makes much more sense to base it on a non-integer, with linear interpolation used to calculate the value at any time in the intended range.
So, yes, it really is the most reasonable approach to animate a float, without real framerate dependency, and then truncate the final value to use it as an integer.
But you can go into the curves and set both tangents to constant which makes the float "snap" to the value at the key frame. This functions exactly as an integer would be expected to... I don't see why they can't implement integers and make them behave this way with out being able to be configured otherwise.
Similarly, booleans are already implemented... and they don't have some gradual transition.
The only difference between implementing a boolean and an integer, effectively, is allowing more than two states... and ins$$anonymous$$d allowing an arbitrary number of states.
They decided it was unnecessary? They couldn't find a good standardized way to implement it? Your guess is as good as $$anonymous$$e.
Please mark my answer as correct if your problem is solved.
@biasless
They really should implement integers, but since they don't, it's fairly easy to just use a float and each time you add a key frame that references it, go to the curves screen, right click the frame, go to "Both Tangents" and click "Constant".
If they implemented integers, it'd basically function like that... except you wouldn't need to go into the curves screen each time.... or cast them lol
Thanks for the tip :)
i also wonder about why classes aren't allowed when they get serialized to $$anonymous$$onoBehaviour they lose there links to other unity objects anyway and become like a struct dedicated to the $$anonymous$$onoBehaviour that owns them. then you've got the benefit of reference in custom editors and GUIs and so on. right now i'm just using structs that also have a class version and syncing the changes between them as i animate. (reflections a bit heavy when you have multi layered structs that require setting each layer all the way to the top)
Your answer

Follow this Question
Related Questions
Get Enum member from int 1 Answer
Animation depending on the Int value 0 Answers
Integer value casting to KeyCode enum in JS? 3 Answers
Can't compare byte to byte? 2 Answers