In this tutorial, you will learn:
- How to create a new RTS Engine map scene.
- The general overview and structure of the map scene.
- General structure of UI elements and their purpose.
- Setting up the player’s faction slot.
- Setting up the terrain object to be identifiable by the RTS Engine.
- Baking the navigation mesh of the map to allow unit movement.
We will first start by importing the asset into a fresh new project from the Asset Store. The RTS Engine is complete project and therefore it is recommended to import it into a new Unity project since it will overwrite some of your project settings (which is something that the Unity Asset Store forces for all assets that fall under the “Complete Projects” categories).
Now that the RTS Engine asset is imported. Our first goal is to create a new scene that represents a playable RTS map.
To create a new RTS Engine map:
- Create a new scene.
- Navigate to the RTS Engine menu in the top menu bar and select “Configure New Map“.This will spawn a basic new RTS map so you do not have to start completely from scratch. Your scene should now look like this:
- Save your scene.
We will now explore the structure of a RTS Engine map scene and define the key elements. The way the game object in the scene are organized is not necessary for the RTS Engine to function as it is expected to but having this layout allows you to separate game objects depending on their role. We will now go through some of the most important objects you see in the hierarchy:
- At the top of the hierarchy, we have the “MANAGERS” parent object. Each one of its child objects includes manager components that are responsible for monitoring the state of the game and providing functionality shared by interacting objects.For example, we have the “GameManager” which is responsible for setting up faction slots and general game settings and the “MovementManager” which is queered every time a unit wants to move.
- The “RESOURCES” is supposed to include all of the pre-spawned resource objects in the map so that they can be easily fetched and initialized when the game starts. More on this later when we create our first map resource.
- The “TERRAIN” includes a basic plane mesh that is used as the main terrain for the map. A plane mesh is not the only way to define your map’s terrain. We will see how we can set up the terrain later in this tutorial.
- The “CAMERAS” parent object includes both the main camera that is the main camera used to navigate the map and the minimap camera which is a camera that has an overview of the map and is drawn as a minimap.
- The “FACTIONS” object includes pre-spawned faction entities (one unit and one building) intended to be used as the player’s faction starting entities. We will go through creating units and buildings later.
- And finally, we have the canvas game objects where each one includes UI elements that serve a specific purpose. We will not go in details about the role of each UI element as this is explained in details in the UI Manager section.
- “MainCanvas“: This one includes the main UI elements that the player sees on their screen. Everything from the resources count, selection panel and task panel to the basic controls and pause menus.
- “SelectionBoxCanvas“: The selection box has its own separate canvas and can not be included with any other UI elements.
- “MinimapCanvas” and “MinimapBackdropCanvas“: These two include the UI elements that you see in the minimap (cursor, minimap icons of entities and more) and the backdrop drawn behind the minimap.
- “HoverHealthBarCanvas“: This one includes the hover health bar UI elements. When the player hovers their mouse over an entity, these UI elements display the current health of that entity.
At this point, you should be familiar with the general structure of a RTS Engine map scene.
We will now shift the focus to two manager components: Game Manager and Terrain Manager. When creating a new map scene, it is always a good idea to make sure that these two components are configured first.
Starting with the Game Manager, we will look at some of the fields that are important to know for this beginner tutorial. These fields and the rest of the fields are explained in details in the Game Manager documentation page. For now, the fields that interest us are in the “Faction Slots” section:
- “Add” button: This button allows to add a new faction slots. For now, you can see that there’s just one faction (“Count: 1“). We will keep this way for now since we only want to have one faction for the player.
- “Type“: Here the faction type can be assigned. We will not go through creating faction types in this tutorial and therefore we will keep this one unassigned. But briefly, faction types allow to have specific faction entities (units and buildings) to be usable only when the faction posses a certain type. For more information about creating faction types, check out the Faction Type documentation page.
- “Player Controlled“: Make sure that this field is enabled as we only have faction and we’d like to mark that as the one that the player can control.
- “Camera Look At Position“: This represents the position at which the camera will look when the game starts. By default, this is assigned to the pre-spawned building we have under the “FACTIONS” game object.
- “Default Faction Entities“: Any pre-spawned faction entity (unit or building) must be attached to the default faction entities list in the slot of the faction that it belongs to. We can have faction entities that will only be activated when the faction slot has a specific faction type. But for the sake of this tutorial and since this faction slot does not have a type assigned, we will not go through that.
Moving now to the Terrain Manager. To keep this beginner tutorial simple, we will focus on having ground terrain only (since we will not be creating flying units).
The main thing to know about the map’s terrain is that it can be a Unity Terrain object, a plane, custom mesh or any combination of those. The most important thing is to define your terrain layers in the Terrain Manager and have these layers assigned to your terrain objects.
In this tutorial, we will keep the plane terrain object. You can check that it has the layer “Terrain” and that layer is assigned in the “Ground Terrain Mask” field in the Terrain Manager component.
The rest of the fields are explained in further details in the Terrain Manager documentation page.
In the final part of this tutorial, we will bake the navigation mesh of the map so that units can move on it.
The RTS Engine uses the Unity built-in Navigation Mesh to handle unit movement and in order for units to move on the terrain, the terrain’s navmesh must be baked:
- Select the plane terrain object.
- Open the “Navigation” tab.
- In the “Object” sub-tab, make sure the navigation area of the plane terrain is set to “Walkable” (this will allow units to walk on it).
- Move to the “Bake” tab and click on the “Bake” button.
When the navigation mesh is baked, it saved under the folder where you saved this scene.
Further settings of the navmesh baking process can be found in the Navmesh Unity documentation.
Finally, save the scene and start it.
You can see that the camera’s initial position is focused on pre-spawned building (as assigned above in the faction slot). Select the unit with the left mouse button and move it by clicking anywhere on the plane terrain with the right mouse button.
In the next tutorial, we will learn how to create a new building from scratch.