1. Home
  2. Unity RTS Engine
  3. Buildings
  4. Building Main Component

Building Main Component

Add the Building component to the main building object and configure the building from the inspector.


Building General Settings:

  1. Building Name: The name that will be displayed when the building is selected.
  2. Building Code: Assign a unique code for each building which the system will use to identify the building.
  3. Building Category: The category that this building belongs to.
  4. Building Description: A description for the building that will be displayed when the building is selected.
  5. Building Icon: An icon for the building that will be displayed when the building is selected.
  6. Free Building: If true, then this building will not belong to any faction.
  7. Can Be Attacked: If false, then this building will be immune to attacks from units.
  8. Task Panel Category: When using categories in the task panel (check the UI Manager documentation), this is the ID of the task panel that this building belongs to when it appears while selecting builder(s). Task Panel categories allow to organize tasks based on a criteria that you can decide.
  9. Minimum Center Distance: The minimum distance between this building and any building center (a building center is a building that has the border component, explained even more in the next part).
  10. Force Minimum Distance On Player? If this is enabled then the local player will also have to respect the distance chosen in the above field when placing this building in the game. However if this is disabled then this only applies for NPC players.
  11. Building Radius: This is the radius of the building that units use to interact with the building (when the building is selected in scene view, a blue gizmo sphere will appear in the scene view displaying the radius). Make sure that the radius is bigger than the Navigation Mesh Obstacle component size so that units can successfully interact with the building.
  12. Faction ID: If this building comes ready with the map (for example, the capital building must always be present in the scene when creating it). Then you must assign the faction ID manually. If not, leave this empty.
  13. Placed By Default: Choose whether the building is placed at default (will appear fully built when the game starts) or if it requires builders to build it. This also applies to buildings that you want them to be pre-existing in the map.
  14. Population Slots To Add: A building can increase the maximum population amount for a faction by setting this field to the amount that it adds.

Building Resource Settings:

  1. Building Resources: How much resources does it cost the faction to place this building? Enter the name and the amount of the resource that this building needs to be built.
  2. Bonus Resources: A building can affect how fast units could collect resources in its area (its area is determined by the size of the border that belongs to the nearest building center). For example, to increase collecting Food resources, you would just type: “Food” in the Name field. And then type how much you need to increase its collection per second in the Add Collect Amount Per Second field.
  3. Is Resource Drop Off: Choose whether you want resource collectors drop off their resources at this building or not. This option is not needed when you choose resources to be automatically added to the faction while collecting (See the resources section for more information about resource collection methods). When enabled, this option will show a list of other options regarding the resource drop off process:
    1. Drop Off Position (optional): In case you want to use a static drop off position, you can use a child object of the building as the drop off position (use example: this building is a warehouse where units can drop off resources and you only want units to drop resources at the warehouse door). When this is not assigned, the unit will simply move towards the building and once in range of the building the unit will drop the resources off.
    2. Accept All Resources: When enabled, the building will act as a drop off building for all types of resources. When disabled, the “Accepted Resources” array should appear in the inspector in which you can enter the names of the resources that the building will accept.
  4. Place Near Resource: When disabled, the building can be placed anywhere depending on the other settings. Once this option is enabled, you’d need to a resource type name and the allowed range to that resource type at which the building can be placed. This is useful in the case where you want to place a certain resource type warehouse near the resource only.

Building Health Settings:

  1. Maximum Building Health: Maximum health points for this building.
  2. Minimum Health To Launch Task: Minimum health points required for this building to be able to launch tasks (Building tasks are explained right in the next part).
  3. Hover Health Bar Height: When moving the mouse over a building’s object, a health bar would appear. This is the health bar’s position on the y axis.
  4. Building States: Depending the building’s health, you can show and/or hide parts of the building (such as fire particle effects or smoke when the building is badly damaged). Therefore, you need to create an empty object and make it a child object of the main building’s object. Then drag and drop this object into the “Building States Parent Obj” field. All the building states objects must be children of that object. You can have as many building states as you need. For each building state, you must assign an interval of health (“Min Health” and “Max Health” at which this building state is active. You must also assign which objects will be shown (“Parts To Show”) and which ones will be hidden (“Parts To Hide”) when the building state is active (when the health is inside the specified interval). When a building moves to another state, the last parts that were shown will be hidden and the parts that were hidden will be shown.
  5. Building Destruction: When the building’s health is 0. The building will be destroyed. This destruction can be improved by assigning an audio clip in the “Destruction Audio Effect” that will be played and assigning a “Destruction Object” that will be spawned when the building is destroyed.
  6. Destroy Award: This array allows the faction that destroyed this building to get resources as a reward. The resource types and their respective amounts can be assigned inside this array.

Building Upgrade Settings:

  1. Upgrade Building Directly: If false, the player won’t be able to upgrade this building directly.
  2. Upgrade Building: The target building to upgrade to.
  3. Building Upgrade Resources: The resources required to upgrade this building.
  4. Upgrade Required Buildings: The buildings that must be spawned to launch this upgrade.
  5. Building Upgrade Duration: Time required to complete the building’s upgrade.
  6. Upgrade All Buildings: If true, then this upgrade will trigger all upgrades on other buildings (even the ones that can not be upgraded directly).

Building Tasks:

  1. Max Simultaneous Tasks: The maximum amount of the tasks that can be run at the same time.
  2. Building’s Tasks: First set the amount of the building’s tasks by changing the size of the “Building Tasks List”. And for each task, assign:
  3. Faction Specific: If the task is faction type specific, then set this to true.
  4. Faction Code: If the task is faction type specific, then set the code of the faction where this task is available.
  5. Task Description: A short description for the task that will appear when the player’s mouse is over the task icon.
  6. Task Type:
    1. Unit Creation: produce units
    2. Destroy: building self-destruction
    3. Research: apply changes to units attributes
  7. Task Panel Category: When using categories in the task panel (check the UI Manager documentation), this is the ID of the task panel that this task belongs to when it appears while selecting this building and displaying its tasks. Task Panel categories allow to organize tasks based on a criteria that you can decide.
  8. Upgrade Task Panel Category: Same thing above but for upgrades for this task (because they do appear as a separated task).
  9. Task Icon: The icon that will appear in the building’s task panel.
  10. Required Resources: Which resources and how much of these resources does the task need.
  11. For the “Unit Creation” task type: Assign the unit’s prefab that will be created in the “Unit Prefab” field.
  12. For the “Research” task type: Set the units that you want to be affected by this research task (simply drag and drop units into the “Unit List” array) then set the values that you want to change (either positively or negatively). Values that can be affected are currently: Speed, Unit Damage and Building Damage.
  13. Reload Time: How long does this task take to take effect?
  14. Task Completed Audio: Audio clip played when the task is done.
  15. Task Upgrades: Each “Unit Creation” task can have multiple upgrades. This means that the player can launch an upgrade task in order to change the effect of one of the tasks and make it produce another unit. In order to create upgrades for a task, set the amount of the “Upgrades” array of this task (you can have as many upgrades for each task as you want):
    1. Target Unit: The Unit prefab that will be produced when the upgrade takes effect.
    2. Upgrade Resources: Which resources are required to apply this upgrade.
    3. Upgrade Icon: The icon of the upgrade task that will appear in the “Task Panel” when the building is selected.
    4. New Task Icon: The new icon of this task after the upgrade.
    5. Upgrade Description: A short description for the upgrade task that will appear when the player’s mouse is over the upgrade task’s icon.
    6. New Task Description: The new description of this task after the upgrade.
    7. New Task Resources: The required resources of this task after the upgrade.
    8. Upgrade Reload: The time needed in order for this upgrade to take effect.
    9. New Reload Time: The new reload time for this task after the upgrade.
    10. When an upgrade is applied in one building, it will be also applied in all buildings of the same type.
    11. Handling building tasks in game (launching them, canceling them, etc..) is explained in the UI part of the documentation.

Building Components:

  1. Building Model: Drag and drop the building’s model object in this field (it must be a child object of the main building prefab).
  2. Building Plane: This is the object that hold the selection texture and which will be activated when the building is selected. This object includes a mesh renderer as it will be colored in the faction’s color when activated. Also a child object of the main building’s object and has “Building” as its layer.
  3. Building Selection Component: The selection collider must not be the same as the building’s main collider. Therefore, create a new empty object and make it child of the main building’s object. Then add a Collider to this object (with “Is Trigger” set to true). This collider represents where the player has to click with the mouse in order to select the building and also acts as hitbox for attack objects. Finally, add the SelectionObj component to the selection object and drag and drop this object to the “Building Selection Component” field in the Building component, the SelectionObj component has the following fields
    1. Obj Type: Set to Building.
    2. Minimap Icon Size: Represents the size of the minimap icon for this building.
  4. Construction Object/States: When the building is being built, you have two options: You can either display one static object from the beginning till the end of the construction and that is the “Construction Obj”, or you can change the displayed object of the building under construction depending on its current health to show the progress of the construction:
    1. Construction Obj: Being a child object of the building’s parent object, this object will be shown when the building’s is getting built for the first time. The rest of the building’s model will be hidden till the building is completely built (reaches maximum health). Make sure that this object has the “Default” layer and the “Building” layer.
    2. Construction States: For each state set the object that you want to display (that object must be a child of the building’s parent object and make sure it has the “Default” layer. Then set the health interval at which you want this object to be displayed at.
  5. Building Damage Effect: An object that will be spawned each time the building receives a damage. This object must have the EffectObj component. For more information about effect objects and how to create them, check out this documentation page.
  6. Units Spawn Position: For buildings that can produce units. A position for spawning units must be chosen. Therefore, create a new child object of the building, assign the “Building” layer to it, place it wherever you want the units to appear at when they are created. And drag and drop that object into this field.
  7. Units Goto Position: When the units spawn at their spawn position, you can assign a goto position to them meaning that as soon as they spawn, they will move to the goto position. Create a new child object of the building, assign the “Building” layer to it, place it wherever you want the units to go to after they spawn. And drag and drop that object into this field. You can also assign a model for this object which will appear in game when the building is selected. Right clicking on any free part of the terrain when selecting a building that has a goto transform assigned, will set the goto position to where the player has clicked allowing the player to change the goto position in game.
  8. Faction Color Objects: Drop and drag objects that have a “Mesh Renderer” or a “Skinned Mesh Renderer” component that are children of the main building object and that you want to color their mesh with the color of the faction. For each one, specify the ID of the material that you want to color.

Audio Clips:

  1. Selection Sound Effect: Audio clip played when the player selects this building.
  2. Launch Task Sound Effect: Audio clip played when a task is successfully launched.
  3. Declined Task Sound Effect: Audio clip played when a task can not be launched for any reason (insufficient resources, etc..).

Right after creating the building, drag it to the project and create its prefab.

How can we help?