Add Unit to Map
Go ahead and load a map scene. For this tutorial, we will be loading the tutorial_map created in the Set New Map tutorial.
1. Add Unit to Faction Slot
In the Setup Faction Slots tutorial, we went through setting faction slots up for a map scene where we've dealt with setting pre-placed (or initial) faction entities for each slot. In short, the initial faction entities are units and buildings that a faction starts with. These need to be to set in the Game Manager component.
Select the Game Manager object and expand the player's faction slot (it is the one where the Is Local Player field is enabled. In the tutorial_map, it should be the first slot):
We want to remove the new_unit faction entity from this list and delete its object from the scene first. Since the new_unit is also assigned to the Initial Cam Look At Position of this slot, then replace it with the tutorial_building object so that the player's camera will initially look at the building object when the scene starts. Feel free to also remove the new_unit_secondary unit from the scene and from the Type Specific of the initial faction entities Field.
Now it is time to add the new unit prefab. For this tutorial, we will be adding the tutorial_unit created in the [previous section of this tutorial](xref:uid: Units_CreateNewUnit). Find the tutorial_unit in the project tab and drag it into the current map scene. To keep things organized, we will keep it as a child object of the Factions object in the scene, where all other initial faction entities are placed. Place the unit at position (40,0,40) then duplicate the unit multiple times so we end with a group of the same unit type. Your scene should look something like this now:
The next step is to add the units to the faction slot's Initial Faction Entities in the Game Manager component so that they would be properly initialized as part of that slot.
Now start the scene and you should be able to select units individually or in a group (by holding down the left mouse click and dragging the selection box through the screen). This means that the units have been correctly initialized. Now select the units and try move them to a destination with the map's terrain. Notice how the units will pick their path destinations in a row destination, this is because we assigned them the Row formation type in the last tutorial where we configured the unit's movement.
2. Add Unit to Free Faction
Units can also be added to a map scene without having to belong to any faction slot, in this case, they are referred to as free units. To add a free unit, drag and drop the tutorial_unit's prefab into the map scene and set its position to (50, 0, 55).
In order to initialize the free unit properly, it needs to be added to the Free Units array field of the Unit Manager component which can be found under Game Manager -> Essential -> UnitExtension. In the same component, the Free Unit Color field allows you to set a special color for all free units in the map scene. As for the Default Anim Controller field, it refers to the animator override controller that will be assigned which does not have one by default. We went through the unit's animation setup and override controllers in this section of the tutorial.
Here is how the game should look like after adding the free unit:
Download Files
You can download the results of this tutorial here.