NPC Unit Regulator
The NPC Unit Regulator allows to handle the creation of unit entities for the NPC faction. Each unit type that the NPC faction is allowed to create has its own regulator.
In this guide, we will setup a unit regulator for the tutorial_villager unit.
1. Create NPC Unit Regulator Data
The NPC Unit Regulator Data is responsible for regulating the creation of one or multiple unit types for one or multiple NPC types, one or multiple faction types or a combination of those two.
To create a new NPC Unit Regulator Data, right-click with the mouse in the project tab and click on: Create -> RTS Engine -> NPC Unit Regulator Data. An asset file will be then created, select it and define the new unit regulator fields.
Call it tutorial_npc_villager_regulator for example. Select it and let's explore its fields:
- Min Amount Range: Minimum amount that must be created from the unit type.
- Max Amount Range: The maximum allowed amount that can be created from the unit type.
- Max Pending Amount: The maximum allowed amount of this unit-type-creation tasks that the faction can have at the same time.
- Create On Demand: Allow NPC components (other than the NPC Unit Creator component, the component responsible for creating units, which we will get to later) to request the creation of this unit type.
- Start Creating After (in seconds): The creation of this unit type will start after the delay provided in this field.
- Spawn Reload Range (in seconds): The timer length that will be used by the NPC Unit Creator component to decide whether to create this unit type or not.
- Auto Create: Enable/disable the creation of this unit type by the NPC Unit Creator component.
- Faction Entity Requirements: Input a list of required faction entities (defined by their codes and/or categories) with a specific amount that must be available and present for the NPC faction to create the unit regulated by this data.
- Ratio Range (between 0.0 and 1.0): The ratio of the amount of this unit type to the amount of the population slots which determines the target amount to create from the unit type. If the target amount determined by this ratio is below the minimum amount (above the maximum amount), the NPC Unit Creator component will set the target amount to the minimum amount (to the maximum amount).
We will configure the tutorial_npc_villager_regulator data fields as the following screenshot: You can of course tweak these values for different effects.
2. Configure Unit Prefab
Now we need to assign the regulator data to the unit prefab. Open the tutorial_villager unit prefab and add the NPC Unit Regulator Data Input component to its parent object.
In this component, you can assign a NPC Unit Regulator Data asset file to be used for the unit for all types (all NPC and faction types) or go into the Type Specific field to pick what NPC Unit Regulator Data asset files can be used for certain NPC and faction types. We will just add a new element to the Type Specific field and link the regulator data asset we created to the tutorial_npc_type that we are dealing with in this tutorial. So the new NPC Unit Regulator Data Input component should look like this now:
- Faction Types: Set to All because we want to assign the regulator data no matter the faction type of the NPC type.
- NPC Types: Set to All In List and in the Options list, add the tutorial_npc_type. This would ensure that the regulator data is only used with the NPC type we created.
Download Files
You can download the results of this tutorial here.