Before 2DToolkit, I was using Unity’s own 2D functionality for the game. By this stage I already had built 2 levels and the base abilities (lasers, sword spins, speed rails) for Gunkatana.
I wanted to create a way for CrazyArcadia (the artist working with me) to create his own levels within Unity without requiring my engineering.One of the big failings of Unity’s current 2D tooling is the lack of tiled sprites. However, their UI system, released later, allows tiling of sprites.
So I bootstrapped a wall tiling tool on top of the UI image component. It wasn’t good enough, due the various ways that the Unity UI can be displayed on the screen, the different measurement systems, it didn’t work as smoothly for level creation.So I just went and bought 2DToolkit.
2DToolkit’s has a great tiling feature for sprites. It also includes a fantastic way to organize your art.Instead of relying solely on where sprites are on the project, you can group multiple sprites into collections, which are then packed into atlases.
Tip: each atlas visible in the viewing frustrum will count as a draw call.
It really makes it easy to catalog and organize your sprites by their domain, be it characters, world details, objects, etc, and then when you’re using 2DToolkit’s sprites, you get a dropdown box with all of your sprite collections.
It also includes animation support. You create animations in separate animation libraries, ideally only animating things from one specific collection / atlas.
Then you can attach a 2DToolkit sprite animator to a gameobject with a 2DToolkit sprite, and on that animator you get a dropdown box with all the animation libraries and can pick which animation you want.
This makes short work of Unity’s builtin animations, which all require different objects and have to be animated on the target object. You can setup your whole sprites and their animations without touching any gameobject, so it’s all ready for when you start assembling your prefabs. Or, you can access it programmatically, which is what I ended up doing.
When a player selects a character and a skin, their ids are stored in the
PlayerSelectModel. When a character is spawned into the level, I get the
correct animation library for that particular character and skin that I have
setup in a ScriptableObject, loaded asynchronously when you start the game.
As I converted my player object to use 2DToolkit, I needed an easy way to create multiple animation libraries with the same sprite ids from a large character atlas, but aiming at a different sprite.
Sprite collections also allow you to define specific collision boxes on different sprites.This is very useful if your entity changes shape as it animates and you want the collision box to accompany it. The classic example of these changing colision boxes are Street Fighter 2’s hitboxes.
So I edit the actual prefab files in a text editor to point to the correct sprite collection.I’d love to create an automated tool to do this for new skins!
Sprite Collection Clone Workflow
- Create new Sprite Collection with same properties
- Add the new spritesheet.
- Copy data from the Sprite Collection prefab that already has all collisions setup onto the new Sprite Collection prefab (using a text editor)
- Change the sprite’s fileID and guid using find and replace all to point to the sprite atlas you want.
Example: spriteCollection: {fileID: 11422796, guid: 7e8e615b27635412c8c23a07b136537d, type: 2}
The new sprite collection will have the collisions and will use whatever new spritesheet with the different character’s skin!
Now for animations:
Animation Clone Workflow
- Copy animation library
- Replace fileId and guid with spritecollection you want, defined in the sprite collection prefab
It can be a bit fiddly but it works out in the end.
With this I was able to (relatively) easily add new skins for existing characters in Gunkatana.