Unity RTS Engine

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

Building Main Component

The building’s parent object has the Building component attached to it. This is the main component that defines a building. The building’s parent object must have its layer set to “Building” as well.

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. 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.
  10. 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.
  11. 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 Placement Settings:

  1. 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. This field must be enabled for the capital building that is pre-placed in the map.
  2. Placed Outside Border: Enable this if you want to allow this building to be placed outside the faction’s territory.
  3. Required Buildings: A list of buildings that must be already placed and built in order for this building to be placed. For each element of this array, you can specify a name and a group of buildings. When attempting to create this building, each element of the array will be used like the following:
    1. One of the buildings in the “Building List” must be present.
    2. The “Name” field will be displayed in the UI.
  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. This field will be ignored by NPC factions as the creation of buildings is regulated by the NPC Building Regulator which defines the placement info of the building.

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.

Building Health Settings:

  1. Maximum Building Health: Maximum health points for this building.
  2. 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.
  3. Destroy Object: When disabled, the building’s object won’t be destroyed when the building has zero health
  4. Destroy Object Time: After how much time (in seconds) should the building’s object be destroyed after it hits zero health (if the above option is enabled).
  5. 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.
  6. 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.
  7. 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 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). The building’s model object must have the “Building” layer. Make sure that when the building’s parent object is placed at the same Y-Axis as the terrain, the building’s model is completely over the terrain and is totally visible.
  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 frontier collider. It’s a child object of the building parent object. It includes a Collider component 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. It also has the Selection Obj component attached to it. The selection object is then assigned to the “Building Selection Component” field in the Building component, the Selection Obj component has the following fields
    1. Obj Type: Set to Building.
    2. Can Select: Can this building be selected?
    3. Select Owner Only: When enabled, only the owner of this building will be able to select it.
    4. 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. Upgrade Launch Sound Effect: Audio clip played when the building’s upgrade has started.
  3. Upgrade Completed Sound Effect: Audio clip played when the building’s upgrade is done.

How can we help?