Animation in Unity
Animation is a useful tool to bring life to any space. This tutorial will cover some basics for doing so in Unity.
Last updated
Animation is a useful tool to bring life to any space. This tutorial will cover some basics for doing so in Unity.
Last updated
At the moment animation made in Unity is limited to your space. As much as you can create artifacts with animation, these cannot be turned into NFTs. If you want to create an animated NFT, you will need to use a different method such as minting the animated blender file as an .fbx or .glb.
1. First, open the Animation window using Window / Animation > Animation.
2. Click on the object you want to animate. In the Animation window, click on the Create button. It will ask you to name the animation and set the location. You will then have a new Timeline to work with, and the object will have an Animator Component.
The animation timeline can use the current object (with the animator component applied) and has access to every child in the object, but none of the objects ‘above’ or ‘below’. If need be, create an empty game object and put all the objects that you want to animate (that are connected in some way) in there. - Object (cannot be animated) - Object with Animator (Can be animated) - Child Object (can be animated) - Child Object (can be animated) - Child object (can be animated) - Object (cannot be animated) If you have many objects or parameters you are going to animate, having many objects in one timeline gets difficult to use very quickly as each element that gets animated gets its own line in the timeline. There are ways around this that I will go into later.
3. If you want different objects to have different timelines (eg. different timing of a loop or less complicated animation), each object would need it’s own animator applied. You would have to add this manually by going to the target object and applying the Animator component. Then reselect the object in question, and the Animation / Create button will be available for that object similar to step 2.
4. You can select if the animation loops or not by clicking on the Animation clip in the Project Hierarchy and toggle Loop Time. You can also set the loop pose for seamless animation and Cycle Offset to set the loop frame different to frame 0.
5. Select the object with the Animator component once more. Select the red record button at the top left in the Animation window. Nearly anything you change on your object will create a keyframe, or set animation information on a frame, in the timeline. Many parameters can be animated, from object position to material information, and these can be keyframed with this turned on.
If you want the first keyframe to be set, without changing the parameter, you can move or type in a new unit in the target parameter, then moving/typing in the original unit. You can also right click on the parameter (the ‘x’ next to parameter slot for example) and select Add Key.
6. Move the Animation player head using left mouse at the top of the timeline to the next keyframe location. Modify whatever parameters you would like to animate, and as the Record button is on, the changes will be keyframed automatically.
1. Use scroll mouse to zoom in and out of the timeline
2. Hold down middle mouse button to pan the timeline left and right
3. Left click and drag to select multiple keyframes
4. Left Click and drag at the top of the timeline to move the play header
5. Use the Space bar to play the animation (when the animation panel has been clicked)
6. Use the buttons next to the Record button to skip to the First/Previous/Next/Last keyframe. This is particularly good for making sure you are lining up keyframes with other keyframes, as this gets harder to do with longer timelines.
1. Select the keys at the top to select all keyframes on that line
2. Ctrl + C to copy keyframes
3. Ctrl + V to paste keyframes
4. Drag keyframes using left mouse button
5. Select a range and use the bars to stretch keyframes
6. Note that the timeline has different keyframe handle types, by default it is Clamped Auto, so it will slow down towards the keyframe, and speed up as it moves away from it. If you want a smooth constant loop you can right mouse click on selected keyframes, and apply Auto. Free smooth, Flat, and Broken are also available. For more information on these, check out the examples in the Unity documentation Here.
7. If you click on the arrow next to each object to the left in the Animation Panel, you have access to each individual parameter to animate.
8. At the bottom of the left side of the Animation panel is the option to go to Curves Mode. This will allow you more control over how your animation keyframes work and give you complete control over the keyframe handles.
9. If you select the elements and press ‘F’ it will focus on that information (this work on the Dopesheet as well).
10. Edit the curve sheet keyframes and handles as needed with left mouse button.
11. Right Mouse click to add a Key
12. Press Delete to delete a key (after selecting it)
13. As noted, right mouse click access handle types, the Curve sheet allows manual modification of the handles depending on the handle type.
Move the timeline to where you want the next frame to be, and move, rotate, scale your object as you see fit. Continue until your animation is complete. If you are wanting to create a full rotation, note that copying the first keyframe to the end of your loop will not work as that will be more like a boomerang effect, you will need to rotate the object the full 360 degrees (in comparison to 0 from the first frame) for that to work correctly.
Similar to position, select the object with the material you would like to animate, open up the material information and type in the units you would like, or click and move the mouse on the text next to the parameter. In this example, use the first offset parameter (not the second) to 0. Move the header in the timeline to your next keyframe location and then adjust the parameter as needed. If you want the texture to loop seamlessly the parameter needs to be a factor of 1 (so 22, 5, 10 will also have a loop if need be). I use higher numbers if I am trying to loop a number of textures at different speeds for example (one material loops at one where another is at 4 which would be 4 times faster).
Most, if not all, parameters that are accessible on the material can be animated, such as color, emissive level and emissive color, and tiling for example. Use them in creative ways to get the effect you are after!
NB : Sometimes if you animate one material on an object, other objects with the same material will also animate at the same time. So in some cases you may need to separate objects into different animation components.
A more advanced trick of animating textures is using more strategic unwrapping of the object to have one material scroll one way (as it can only be in one direction) but display the material moving in different directions on the object, even though it only one material (which saves materials, which in turn saves draw calls, which is a lot more optimised use of animation).
Basically using the UVMap to define the direction of the texture animation, rather than having multiple materials animating in different directions.
It is possible to put an animator layer on a child object so that it has its own loop and then be controlled by the parent animation. Say you want a fish swimming loop (on the fish itself) and then the animated path of the fish on the parent object (you could have three fish as children on the parent object for example.