NPC Unit Creation
1. NPC Unit Creator
Open the tutorial_npc_manager prefab and find the NPC Unit Creator on the NPC.UnitExtension child object. This component is the one responsible for the creation of units for NPC factions.
- Default Regulator Data: In case this component or any other NPC component attempts to create a unit that does not have valid regulator data defined and this field is assigned, the regulator defined here will be used for that unit.
- Independent Units: Unit prefabs that this component is able to create independently from other NPC components. Unit prefabs that are assigned to other NPC components (such as resource collectors or builders) are not required to be added to this list. Here you can add the tutorial_villager unit, for which we set up the NPC Unit Regulator Data for the tutorial_npc_type. This means that the NPC faction will be creating the tutorial_villager unit based on the regulator data we set up in this previous section.
- Population Resource: Capacity resource type that is used as the population resource. If this is not assigned, the NPC faction will aim to create just the minimum amount of each unit type. Since we are using demo entities in this guide, we will asssign the population resource type here.
We also want to enable all the logs data so that when the game is running, we can follow the decisions that the NPC faction is making in regards to unit creation:
2. Testing
Now open the map scene and play it. In the hierarchy, find the the tutorial_npc_manager instance and find the NPC Unit Creator attached to its NPC.UnitExtension child object:
In the inspector, go to the Logs tab and you should see NPC Unit Creator at work:
- Active Unit Regulator Logs: Each element of this list represents a unit that is being handled by the NPC Unit Creator. Here we see we only have one element, which is the tutorial_villager unit. And we can also see the attributes assigned to this unit's regulator such as the maximum pending amount, minimum and maximum allowed amounts. This also shows us the target amount that the NPC faction is aiming to create for this unit as well as the current amount and the current pending amount. Finally we have a list of Creators which show us the currently available Unit Creator components for the NPC faction that can create this type of unit and the spawn timer which is the period at which the NPC faction considers creating a new instance of this unit type.
- Event Logs: This list shows us, with timesteps, the decisions that the NPC Unit Creator is taking. In the first one, we see it has recongized the tutorial_villager unit regulator and activated it. Then we see it successfuly launching unit creation tasks for it.
Your scene should look similar to this by this point:
Download Files
You can download the results of this tutorial here.