Sprite Sorting Layers

Where we set our sprite layer.

One of the issues faces in our Laser Defender game was the fact that our laser sprites were spawning on top of our ships (both player and enemy).  It was a minor issue, but for the purposes of polish it’s nice to be able to fix these things.  Enter Sorting Layers.

Unity allows us to define a vertical stack that it will draw your games sprites into.  It’s a much easier and cleaner method of ensuring your images enter the game world at the right level than relying on the Z axis for 2D games.  Also, it’s set directly on the sprite renderer so it’s easy to find and read as well as being able to set it in your prefabs.

In the course example we created layers for the enemy ships, enemy lasers, the player ship, player lasers and finally (not shown) an explosions layer at the very top.  I’m fairly certain we could have trimmed this down to just ships, lasers and explosions, but I may discover the reason we made this so granular in a later lesson.

The location of our sprite layer menu.
An example of some sprite layers. Layer 0 is at the bottom, Layer 4 the top.

It’s simple to find in the menu system, and the layers are draggable if you need to re-sort them at a later date.

I’ve added a new category for these kinds of posts where I just talk about simple things for the purposes of helping me understand them better.  As a solo-dev, these are basically my version of “Rubber Duck Debugging” applied to the learning process.  Feel free to skip over the “Self-Explaining” posts in the future!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.