Implementing a Reload Animation in Unity!

Marcus Ansley
3 min readAug 31, 2021

I recently implemented this reload animation to the First Person Shooter project I’ve been working on for the GameDevHQ course. Essentially, this consists of an Animation (made in unity), an Animator Controller, and a script adjustment so that the ‘R’ key triggers the animation.

Animation

With an object with an Animator component selected (in my case, the gun itself), we can head into the Animation window and click to ‘Create [a] New Clip’. It’s most likely going to be easiest to set this animation up in Play mode, so I’d recommend hitting Play and locking the Animation window using the padlock icon (this’ll prevent the window from changing if you select another object).

If we press the record button, we can set the keyframes for all of the objects in our animation (in this case, the HandPosition objects we created previously and the Gun model itself). We might also want to set the position of the top of our gun and the clip in this case, as this’ll help us properly recreate the mechanics of reloading a pistol.

This could take some time and finessing, but the main thing is to start by setting our start and end keyframes, then working on the middle of our animation clip to position the gun and hands accordingly. For the clip-reloading effect, this is really just the same clip being moved out and back into the gun (creating the illusion of loading a new clip). The top of the gun can also move out whilst we’re reloading the gun, then slot back into place as soon as the clip is loaded.

I personally needed to add in quite a few extra keyframes, particularly on the hands, just to get them to move a bit more convincingly, but feel free to return to this step later if you’d prefer to tweak it once it’s all set up.

I personally needed to add in quite a few extra keyframes, particularly on the hands, just to get them to move a bit more convincingly 😛

Animator Controller

For the Animator Controller, we’ll want to drag in our newly-created Reload animation into the Animator window in order to create an Animation State. We’ll now need to create some transitions to and from this state, returning to our ‘Idle’. As a condition on the transition leading into this Reload state, add in a trigger called “Reload”. You’ll also likely want to disable ‘Has Exit Time’ on this, just so that the player can immediately trigger this animation as long as they’re in Idle.

All that’s left after this is to actually call this Reload trigger from a script 😉

Script

Feel free to add this code to whichever script you feel it should most appropriately be in; all we need is a reference to the Animator component the Animator Controller’s on (in this case, the gun itself), and an Update method to add the following:

With this all done, head back into Unity, let it compile, and ensure this Animator variable is assigned in the Inspector. You should now be able to load up the game in Play mode and press R to trigger your new reload animation 😉

--

--

Marcus Ansley

Game Developer | Game Design and Literature Graduate