1. Home
  2. Unity RTS Engine
  3. Third Party Support
  4. Fog Of War

Fog Of War

This documentation page includes instructions on how to integrate BrendanL.K’s Fog Of War asset and the RTS Engine and how to make them work together.

Fog Of War copyright © BrendanL.K.

Required asset versions:

  • Fog Of War: v1.13
  • RTS Engine: v1.2.3

Links:

Fog Of War asset page

Integration Pack download

Integration Instructions:

Import Files:

Download the integration pack using the link above and make sure that both the RTS Engine and the Fog Of War are already in your Unity project. Then import the integration pack to the project.

Add the “RTS_FoWManager.cs” as the last component in the script execution order in your project (Edit -> Project Settings -> Script Execution Order).

Set up a map/scene:

Create a new empty object in the map, call it “FoW Manager” and add the “RTS_FoWManager.cs” component to this object and configure it:

  • Free Portals Visible: When enabled, all portals (buildings that have the “Portal.cs” component) that are marked as “Free Buildings” (not controlled by any faction in the game) will be visible to all players by default and will not be hidden by the fog.
  • Global Fog Strength: When this option is enabled then all units/buildings will have the same minimal fog strength (if an enemy unit/building in an area in the map where the fog strength is above the chosen value then it will be hidden). The minimal fog strength must be between 0 and 1 with 0 being completely hidden by fog and 1 being completely shown).

Modifying RTS Engine compenets:

In order to avoid allowing the player to place buildings in areas that are still hidden by the fog and not yet discovered by the player, a modification in the code of the “Building.cs” component is required:

Open the “Building.cs” component and search for “FoW Only” and un-comment the code that is FoW related:

  • “FoW” namespace: the code below

should look like this:

  • Building placement: the code below

should look like this:

And make sure to replace “MIN_FOG_STRENGTH” to a value of your choice (between 0.0f and 1.0f). The MIN_FOG_STRENGTH represents the minimal strength of the fog in the area that the player will place the building at. Having it set to 1.0f means that that area must be 100% discovered.

Configuring units/buildings:

Add the “FogOfWarUnit.cs” component to the main object of each unit and building (both the prefabs and the ones pre-placed in the map).

  1. You don’t need to set the “Team” field in the Fog Of War Unit component as it will be automatically set during the game.
  2. Set the other settings (mainly the “Radius” field) to whatever suits your game.

Add the “RTS_HideInFog.cs” component to the selection object of each unit and building (both the prefabs and the ones pre-placed in the map).

  1. Min Fog Strength: Must be between 0.0 and 1.0. This defines the strength of the fog at which the enemy unit/building is visible to the player. (If the Global Fog Strength in the FoW Manager component is enabled, then the value chosen in the manager’s inspector will overwrite this).
  2. Affect Objects: Add the “RTS_HideInFog.cs” component to all children objects that have the “Mesh Renderer” or the “Skinned Mesh Renderer” components of the unit/building prefab and then drag and drop these objects to the “Affect Objects” array field. This allows only the selection object to check whether the unit/building is in fog or not and will apply the same result (either by hide or show) to all objects listed in the “Affect Objects” array.

The “Check Prefabs For FoW” button in the FoW Manager’s inspector allows to check all unit/building prefabs and see if both components above have been added. If not it will return an error with the unit/building’s name and the missing component.

 

How can we help?