Fog of war
Fog of war hides the map except where the player has been. Explored places stay visible.
Add it
Select the map (or minimap) and press Add Fog of War in its Inspector. It explores around the object the map follows, so on the minimap that is the player. Press Play and walk around.
Settings
The Map Fog component has these fields:
Field |
What it does |
|---|---|
Explorer |
The object that reveals the map. Filled with the map’s Follow object when you add the fog. Empty: nothing
is revealed by itself, and you call |
Radius |
How far around the explorer the map is revealed, in metres. Default 40. |
Softness |
Softness of the edge of the revealed area, from 0 (sharp) to 1 (fades over the whole radius). Default 0.3. |
Color |
Colour of the unexplored map. Its alpha sets how much it hides (1 hides fully). The default is a dark blue-grey at 0.92. |
Metres Per Cell |
Size of one cell of the explored mask, in metres. Smaller gives finer edges and uses more memory. Default 2. |
Markers and icons under the fog
Markers you add from code (AddPoint, AddLine, AddPolygon) are hidden by the fog together with the map.
A Map Icon is a UI object, so it stays visible unless you tick its Hide In Fog option.
Save and load the explored area
Save returns a small byte array (a few KB) that you store with your save game. Load puts it back, even before
the map has finished loading. Load throws an ArgumentException if the bytes are not a fog save or come from a
map of another size.
byte[] save = fog.Save(); // store it with your save game
fog.Load(save); // restore it
bool seen = fog.IsExplored(enemy.position); // true once the place is more than half revealed
Reset and reveal
fog.Clear(); // hide everything again (new game)
fog.RevealAll(); // show everything
fog.Reveal(shrine.position, 60f); // reveal a disc of 60 metres
fog.ExploredFraction gives the share explored, from 0 to 1, for a “map 42% complete” display.
On a real-world map
The fog covers the terrain of a map baked from your scene. A real-world map (see Real-world maps) has no terrain, so give the fog an area with two opposite corners, in degrees, and reveal places from code:
fog.SetArea(MapCoordinate.LngLat(11.20, 43.75), MapCoordinate.LngLat(11.30, 43.80));
fog.Reveal(MapCoordinate.LngLat(11.25, 43.77), 200f);
Without an area you get a warning in the console and no fog. SetArea clears what was explored.