In this project we will create and configure a new project to hold our Tactics RPG game engine. We will add folders for organization, import some existing assets, and create a few more assets which we will begin implementing in future lessons.
Project Creation
Open Unity and choose the New Project button from the initial dialog. Alternatively if Unity was already open you can use the menu bar File->New Project…. Provide an appropriate project name and location in the dialog which appears, leave the default mode to 3D, and then click the Create project button to confirm your settings.
Folder Setup
Project organization is very important, and becomes increasingly important as your project grows. Whenever I create a new Unity project, I usually begin by creating a few folders I know I will use in order to help encourage proper habits.
To create a folder you can either right-click inside of the Project pane and choose Create->Folder from the context menu, or use the button just beneath the tab at the top of the project pane.
Start by adding the following folders:
- Editor
- Materials
- Prefabs
- Resources
- Scenes
- Scripts
- Settings
- Textures
For the most part you can name your folders and organize your project however you like, but it is worth pointing out that two of these folders, Editor and Resources are special to Unity. Click Here for a more complete list of Unity’s special folders and their purposes.
If you accidentally nest the folders when creating them, you can click and drag the folder back out to the root level from within the project pane. While dragging, a thin blue line will indicate moving a folder parallel to another folder and a thick blue line over a folder will indicate you would be making it a sub folder.
Import Assets
It is relatively common to start a project using existing assets or plugins. I have created a few to help get this project started.
02_TacticsRPG_Scripts.zip – This .zip file includes a collection of scripts which I initially created in some older posts (Dynamic Animation Part 1 and Dynamic Animation Part 2) as well as a few extras we will use for our animation needs. I added some folders to my project hierarchy such that these scripts are placed in Scripts/Common/Animation. The Common folder is used to organize scripts which I might use across multiple projects, and then the Animation folder just keeps all of the scripts bundled together.
02_TacticsRPG_Textures.zip – this .zip file contains a few textures we can use for our UI and for the game board tiles. I added a folder inside of Textures called UI and placed all textures there with the exception of Dirt.png which I left in the root of the Textures folder.
Note that you can use Unity’s Asset Packages for exporting and importing assets, and they will maintain things such as folder hierarchy, import settings etc. However, I decided not to use them just in case forward compatibility might be an issue.
Modify Texture Settings
Multi-select all of the UI textures we just imported. Change the Texture Type from Texture to Sprite (2D and UI). This step is required in order to use our textures in Unity’s new UI components such as Image.
Set the Packing Tag to UI. This causes all of the images to be saved to a single texture called a Sprite Atlas for optimization sake. Note that this feature is currently not compatible with textures located in the Resources folder.
You can view the atlases which Unity has created to verify that everything is working as you intended. From the menu bar choose Window->Sprite Packer. The atlases are auto created when entering play mode or by creating a build of your project, but you can also trigger their creation by clicking the Pack button in the top left of this window. There should be an atlas for each of the packing tags you have specified, and you can view the corresponding atlas from the View atlas: pull down menu.
Several of these textures will have an Image Type set to Sliced which allows the textures to stretch in specified areas, while keeping the corners unstretched. You can modify the slice locations by selecting a single sprite and then clicking the Sprite Editor button from the inspector pane. In the Sprite Editor dialog which appears, adjust the Border values L, T, R, and B which stand for Left, Top, Right, and Bottom. As you manipulate the values you should see green lines overlay your sprite indicating where the slice will occur. Following is a list of images which need slicing data, and the values used in L,T,R,B order:
- AbilityMenu {44, 42, 1, 32}
- ActionNameBacker {8, 0, 8, 0}
- BlueAttackPanel {3, 0, 47, 0}
- ConversationPanel {71, 70, 2, 70}
- RedAttackPanel {3, 0, 47, 0}
Create Materials
In the project pane, select the Materials folder and then from the Create button choose Material. This should create a new material inside of the appropriate folder. Name the material Dirt. There is a round mark to the left of Albedo – tap this mark to open up the Select Texture dialog, and select Dirt. Since Dirt isn’t shiny, set the Metallic Smoothness to 0.
The Dirt material will be used as a placeholder on the board tiles we create. It is a simple brown texture with a darker border to help visually differentiate where tiles are located.
Next we will create two materials which will help identify the hero units vs the enemy units. Name them Ally and Enemy and drop the Metallic Smoothness to 0.25. Give the Ally a green color on Albedo such as RGB {86, 200, 88}. Give the Enemy a red color on Albedo such as RGB {183, 43, 61}.
We will let our units share a material representing their eyes (we will use this to help determine which way our units are facing). So create another material called Eyes.
Finally, we will use one more material on an object which represents which tile is currently selected, as well as for a facing indicator. Create a new material called Selection and give it a yellow color on Albedo such as RGB {255, 255, 0}
Create Objects
First let’s create the board tile. From the menu bar choose GameObject->3D Object->Cube. Name the object Tile and assign the Dirt material to the Mesh Renderer in the inspector (or by drag and drop in the scene view). Now drag and drop the Tile GameObject from the Hierarchy pane onto the Prefabs folder in the Project pane. This creates a prefab of our Tile. Now you can delete the Tile instance from the Scene (by right-clicking the Tile in the Hierarchy pane and choosing Delete). You will be able to recreate new instances (copies) of your Tile prefab at run time.
Next let’s create a generic unit for our heroes. Start by creating an empty GameObject – from the menu bar choose GameObject->Create Empty. Name the object Hero. This root object will be used as a handle to position the unit on the board. Add another empty GameObject as a child (make one object the child of another by dragging it onto the object in the Hierarchy pane), and name it Jumper. This object will be used to animate the vertical arc of a jump when a Unit traverses between non-level ground. Now create a sphere as a child of the Jumper GameObject – From the menu bar choose GameObject->3D Object->Sphere. Change the Scale of the sphere to XYZ {0.8, 0.8, 0.8}. Assign the Ally material to this sphere. Create another sphere as a child of this sphere to represent an eye. Scale the eye to XYZ {0.25, 0.25, 0.25} and set its Position to XYZ {0.17, 0.32, 0.3}. Assign the Eyes material to this sphere. Duplicate the eye (from the menu bar choose Edit->Duplicate) and move the copy to -0.17 on the Position’s X axis.
Duplicate the Hero and rename the copy to Monster. Change the material on the body from Ally to Enemy. Now drag both the Hero and Monster objects to the Prefabs folder one at a time in order to create Prefabs for each. Delete the original instances from the scene when you are done.
The last object we will make will be an object which marks the currently selected board tile. It will look like there are angle brackets at each of the four corners of a square unit. Start by making an empty GameObject named Tile Selection Indicator. Then add a Cube as a child. Assign this cube the Selection material. Remove the Box Collider Component (Right click its title and choose Remove Component). Change the Scale of the cube to XYZ{0.1, 0.1, 0.3}. Now clone the cube until there are 8 total. Use the following transform values for the cubes:
- Position{0.5, 0, 0.4}, Rotation{0, 0, 0}
- Position{0.4, 0, -0.5}, Rotation{0, 90, 0}
- Position{-0.5, 0, -0.4}, Rotation{0, -180, 0}
- Position{-0.4, 0, 0.5}, Rotation{0, -90, 0}
- Position{0.4, 0, 0.5}, Rotation{0, 90, 0}
- Position{0.5, 0, -0.4}, Rotation{0, -180, 0}
- Position{-0.4, 0, -0.5}, Rotation{0, -90, 0}
- Position{-0.5, 0, 0.4}, Rotation{0, 0, 0}
After modifying assets in your project, you should always save the project itself. From the menu bar choose File->Save Project.
Summary
In this lesson we created our project and got several assets ready for use in the next lessons. We discussed the importance of a well organized project and learned how to create and modify folder hierarchies. We covered how to import existing assets into our project and modify import settings as necessary. We discussed atlases, sprites and sliced sprites for 9-slice stretching in the UI. Finally we created materials and prefabs to represent our game board, units, and a tile selection indicator.
I like your writing style when it comes to these tutorials
Thanks 🙂
@thejon2014 Hey jon. Loving your tutorials.
I may be wrong but i think you forgot instructing us to create a prefab out of the Tile Selection Indicator as well
You’re right, I didn’t specifically call it out like I did with the other prefabs. Good catch.
Love this, thank you so much!!
Spot on. Loving these tutorials so far.
Thank You!
You’re welcome 🙂
Thank you for taking time on doing this!
Also, I think that the links to the .zip files are not working!
You’re welcome! As for the zip files, I just tried them. I see an alert which mentions a problem generating a preview (because its a zipped file), but the download button is still present and working. Maybe try again?
This is brilliant. Still being essential in 2019, thanks Jon!
This tutorial was everything I was looking for, thank you so much for writing it, I wish you the best! ♥
Would this be possible on a 2D setup with Isometric Tiles?
Definitely possible, just know that there are a lot of things you would need to manage yourself that are handled automatically thanks to 3D.
Just another generic Thank you message!
I look forward to learn some insight from your blog.
Bests!
You’re welcome, hope you enjoy it 🙂
Hi Jon!
I’ve had your blog bookmarked for several years now; I’ve always wanted to make a tactics game but never really had the time to invest in it. With current world events, I suddenly have a lot of time to dive headfirst into the whole game development thing! How would you rate the difficulty of making a tactics game such as yours here for a first time developer? Are there other, better places to start if this is my end goal? I’m not really looking to make anything flashy or fancy, just a fun, educational hobby that I can show off to my wife.
I appreciate your work here, thanks!
-Pat
Hey Pat, glad you’ve got some goals and time to achieve them. How new are you? Just new to game programming, or new to Unity, or new to all of the above? The truth is, this is definitely an advanced project. I’ve done my best to make it accessible even to beginners, but there is a LOT of content and advanced architecture covered here.
If you’ve never done anything like this, you may want to start with some of Unity’s own tutorials so that you are at least familiar with the basics. Good luck!
Hi!
This guide is absolutely gold. My biggest thanks for this. I’m curious however that since this is written at 2015, what would you change using the new features Unity provides?
And so, if you will, would you update the guide?
Thank you for your hard work, supporting on Patreon with my first income.
Thanks, and great questions. For a lot of my projects I focus on my own architecture. Of course it is based on some of Unity’s features, but I would consider them more core level features, and is why my tutorials still work and feel relevant after all this time.
If I were to consider core level features that are new in Unity, especially architecturally speaking, I might consider something like DOTS. DOTS is very cool, though at the moment nothing in my Tactics RPG would take advantage of that power. It’s a simple turn-based and event-driven game, so it just doesn’t need that level of performance. If it were real-time with lots of enemies, or maybe needed network support, there “might” be reasons that could persuade me to give it a try. However, it would also require a very drastic change in thinking about the architecture, and a lot of those changes would probably feel more difficult to produce the same end result.
In addition, there are a few other updates here or there, which might actually be nice to implement, such as using Unity’s new Input System and nested prefabs. I would consider those minor updates as they relate to the Tactics RPG project since it is at such a simple prototype stage, but it could still be useful.
I have been interested in updating the Tactics RPG project. It would be fun to actually see it with more completed art as well, even if I just used some simple free assets from the asset store. In addition, it could be nice to implement some missing features, such as menus, missions, the ability to save the game, some sort of world that exists between levels and transitions between them, etc.
Thank you for the answer!
I just have to say that all of that would be awesome. I can’t wait!