FogOfWarManager
The FogOfWarManager component is the core component required for the fog of war system to function. It handles all fog of war calculations and serves as the central configuration point for the system.
Warning
Only one FogOfWarManager instance can be present in the scene at any time. If multiple instances are detected, the system will automatically destroy the entire GameObject containing any duplicate instances, keeping only the first one that was initialized. An error message will be logged in development builds to help identify the issue.
Usage
-
Create a new GameObject and add the
FogOfWarManagercomponent to it. -
Configure the component properties in the Inspector.
Inspector Properties

-
Orientation (enum): Defines the map's orientation plane.
- XZ - For top-down games (horizontal plane)
- XY - For 2D side-scrolling games (vertical plane)
-
Left Bound: The left edge coordinate of the fog-covered area.
-
Right Bound: The right edge coordinate of the fog-covered area.
-
Bottom Bound: The bottom edge coordinate of the fog-covered area.
-
Top Bound: The top edge coordinate of the fog-covered area.
Visuals
-
Camera Tags: A list of camera tags that determine which cameras will render the fog effect. The fog overlay will be applied to any camera containing at least one tag from this list. By default, only the
MainCameratag is included. -
Injection Point: Specifies when the fog effect is injected into the camera rendering pipeline.
-
Color: The RGB color of the fog overlay.
-
Discovered Alpha (0-1): The opacity level for areas that have been discovered but are not currently visible.
-
Fade In Duration (min 0): The duration in seconds for the fog to fade in when an area becomes hidden.
-
Fade Out Duration (min 0): The duration in seconds for the fog to fade out when an area becomes visible.
-
Filter Mode (enum): The texture filtering method applied to the final fog texture.
- Point - No filtering, produces sharp, pixelated edges
- Bilinear - Smooth linear interpolation between pixels
- Trilinear - Highest quality filtering with mipmap blending
-
Blur Strength (0-3): The intensity of the blur effect applied to fog edges.
Performance
-
Texture Size (min 1, max 16384): The resolution of the fog texture (Vector2Int). For optimal results, use power-of-two values (e.g., 512, 1024, 2048). Higher values increase memory usage and computational cost.
-
Max Vision Sources (min 1): The maximum number of VisionSource components that can be active simultaneously. Vision sources exceeding this limit will be ignored (most recently added are dropped first). Higher values increase computational cost.
-
Max Check Points (min 0): The maximum number of visibility check points from VisibilitySwitch components. Check points exceeding this limit will be ignored (most recently added are dropped first). Higher values increase computational cost.
-
Manual Refresh: Enabling this option requires fog updates to be triggered manually via the
RefreshThisFrame()method. -
Refresh Rate (min 0): (This property appears only if Manual Refresh is disabled) The time interval in seconds between automatic fog refresh cycles. A value of 0 means the fog updates every frame.
Public API
-
static FogOfWarManager Instance- The singleton instance of theFogOfWarManager(read-only). Returns the activeFogOfWarManagerin the current scene. -
void RefreshThisFrame()- Forces an immediate fog update on the current frame. Primarily used when Manual Refresh mode is enabled. -
Vector2Int[] GetDataToSave()- Returns the current fog discovery state as a compressed array ofVector2Intranges. Use this data to save the fog state. -
void Load(Vector2Int[] data)- Restores the fog state from previously saved data. Accepts the data array returned byGetDataToSave().