- Home /
Can I create an animation via script at runtime?
Let me explain:
I want to create (or edit an existing) animation and change the sprites, keys, curves, and transform. Is it possible for me to do all this via script at runtime, and if so can someone point me in the right direction because I can't seem to figure it out.
As far as I know there's no way to directly change a .anim file through a C# script. You're better off doing things like this completely by script using variables, lerps, etc.
You mean a manual animation? I can do it, but is there any downsides to this performance wise?
There's no difference in performance. Scripts either set or add to transform properties. Animation only sets transform properties and it's easier to use for specific complex movements but it's inflexible.
Answer by Pinkuboxu · Apr 17, 2019 at 01:10 AM
You will likely want to use Animations you have made in the editor and use the Animator Controller state machine, have script control properties that control blending, speeds, and behaviors. You cannot change parts of the animation you make in the editor as they are read-only. As far as doing anything procedural vs. pre-made (or manual) assets, the performance is always better with a pre-made asset because it's already created and already an asset to be used to and from memory. You don't have to waste run-time cycles on creating it and you don't have to figure out how to get it into memory and then have the system read it at run-time in the case of things that are read-only. You would need a custom system for true procedural animations.
Your answer
Follow this Question
Related Questions
Curves going past keyframes 0 Answers
Can I make animations snap to a frame? 1 Answer
Reading datas from sound files 2 Answers
Edit several animation keys at once 1 Answer
Generic root motion jitter? 0 Answers