Sprite animations in Unity

Unity has two ways to control animations: Animation (old) and Animator (new).

Previously the developer had no other option but to use the Animation component with basic controls for playing a simple animation. This Animation component would have been exactly what we needed, if not for the fact that it does not support sprite animations!

So, the only way to run sprite animations in Unity is to use the Animator.

It does have its perks. It makes it easier to tie together a complex set of animations by creating transition rules and triggers. And if you are working with skeletal animations, you can blend them seamlessly. But for our pixel-perfect 2D game none of that mattered and creating tons of animations this way was going to be a huge burden.

All animated objects would need to have an extra Animator Controller object, each animation would require an extra variable inside the controller just to be triggered to play. Even though these could be computationally generated with little extra work using our legacy data, it was going to make animation management a drag for the future. To make the development process as easy as possible, we needed a different solution.

After lots of pondering, we finally came to the conclusion that we needed to implement our own animation player that would process a set of frames and show them one after another for a predefined duration. This approach would also make it easy to use our game commands system with animations (More about it in another post)!

First we created a data structure for sprite animations and their frames, which was simple enough. Additionally we implemented a way to trigger commands during any frame, which allows for playing sounds, events, etc. in sync with the animation.

Then we created an animation player to process the animation frames in a given order, as well as controls for stopping, pausing and continuing the animation. Our character graphics controller made sure that there was only one animation playing for the given game object at any one time. The background animations were even simpler, as they just loop the same animation repeatedly.

After the compulsory minor issues to crack, all this eventually came together. Now we have a simple and easily modifiable solution for the need of creating and playing simple sprite animations.

Tools: AWE and Dialogger

AWE is the in-house editor and engine upon which everything in Bingwood has been built. It works as a comprehensive resource database for all the images, sounds effects, music files, voice lines etc. allowing the designer to place the resources into the scenes and assign scripts to them. The scene being worked on can be previewed with a push of a button. AWE also boasts a simple animation editor in which the sound effects can be triggered to play during specific animation frames. It also packages the game into a binary file. Games created with the editor are almost completely data driven, which allows for easy porting if the need arises.

AWE

AWE features a scripting language of our own design, with which the whole game has been put together. This intuitive and simple scripting language supports variables, IF-statements as well as several dozens of different commands. An AWE script assigned to a shovel in the game might look something like this:

FUNCTION TAKE
QUEUE1 HERO GOTO -32 76
QUEUE1 HERO FACE “W”
QUEUE1 HERO SAY “This shovel looks useful!”
QUEUE1 HERO ANIMATION “PICKUP” *)
QUEUE1 HERO TAKE SHOVEL **)
END FUNCTION

  • *) Animation calls into action a previously made animation
  • **) Take removes the item from the scene and adds it into the inventory

The Dialogger is another in-house tool used to create dialog trees built up by connecting individual dialogue nodes to each others. Each node contains the actual spoken line (linked to the equivalent voice file), the player character’s reply options and triggers to specific scripted events. Scripted conditions can also unlock previously hidden parts of a dialog or trigger game events. The 2500 lines of dialogue with the accompanying voice files make up more than half of the size of the whole game.

Dialogger

Creating a game with self-made tools has been an educational journey. The tools are far from perfect, some unsavory changes were made as a result of new features being added along the way. These learnings could be used to create a kick-ass sequel editor. It would feature a scripting system working similarly to the Dialogger, being completely visual and doing away with text-based script writing. The resource management and saving/loading system (which caused some gray hairs in this project) would need to be remade from scratch. While AWE was a nice tool to get the job done, it could be polished into a shining jewel.

Yes, the name is an acronym, and we came up with it before the project was actually started. Once we realized that the editor itself wasn’t going to chip in workwise, Adventures Without Effort turned into a much more realistic Adventures With Ease. Be that as it may, Bingwood wouldn’t have been made without it.

Disclaimer: This introduction was written in 2008.