# \[TUTORIAL\] Fog Of War

**URL:** <https://forums.unrealengine.com/t/tutorial-fog-of-war/18222>\
**Category:** World Creation\
**Tags:** unreal-engine\
**Created:** [January 3, 2015, 8:44pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222 "2015-01-03T20:44:57Z")\
**Posts on this page:** 20\
**Page:** 5

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [December 21, 2015, 11:29am UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/81 "2015-12-21T11:29:44Z")

</div>

Wow, ive started ue4 in Compatibility Mode with win 7, and lags dissapeare! O\_o  
What the heck?  
Btw, what version of ue4 are u using?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_02adf4fd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_02adf4fd](https://forums.unrealengine.com/u/anonymous_user_02adf4fd)\
**Post date:** [December 21, 2015, 12:06pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/82 "2015-12-21T12:06:11Z")

</div>

> [@;441083](#):
>
> maybe its caused by dx12, because i have it, not 11

If you’ve enabled Dx11, you could try running the editor normally without the -D3D12-parameter set and see if there’s any difference. Dx12 is supposedly still very experimental and the GPU-drivers are probably not thoroughly optimized.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_02adf4fd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_02adf4fd](https://forums.unrealengine.com/u/anonymous_user_02adf4fd)\
**Post date:** [December 21, 2015, 12:07pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/83 "2015-12-21T12:07:51Z")

</div>

> [@;441085](#):
>
> Wow, ive started ue4 in Compatibility Mode with win 7, and lags dissapeare! O\_o  
> What the heck?  
> Btw, what version of ue4 are u using?

At the moment I use 4.10.1.

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [December 23, 2015, 10:36pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/84 "2015-12-23T22:36:17Z")

</div>

One more question.  
How to make individual sight range for different units in one team?

---

<div class="post-metadata">

**Author:** ![Maxpower13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Maxpower13](https://forums.unrealengine.com/u/Maxpower13)\
**Post date:** [December 25, 2015, 8:03pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/85 "2015-12-25T20:03:14Z")

</div>

Hi, This is my first time using C++ instead of blueprints so I am getting quite stuck :(. I am getting various errors when compiling the code such as “use of undefined type 'AFogOfWarManager” for example, I think it may be due to not changing the correct things in the code or not adding needed things. As I have simply copied and pasted the code it would be really helpful to know exactly what needs to be changed to make it compile smoothly.  
Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_02adf4fd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_02adf4fd](https://forums.unrealengine.com/u/anonymous_user_02adf4fd)\
**Post date:** [December 26, 2015, 12:23pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/86 "2015-12-26T12:23:14Z")

</div>

> [@;442573](#):
>
> One more question.  
> How to make individual sight range for different units in one team?

Hi,

At the moment that capability would require a small rewrite. If you’re a coder, what I’d do is when registering the actor have another parameter for the sight radius. Then I’d store the actors with their assigned sight radius in a hashmap. This would require a little update in the FogOfWarWorker-thread to go from iteration over a list to map and use individual sight radii per registered actor. I’ll probably do that rewrite sometime along with a optimization to decrease the number of traces per actor.

Cheers,  
.

---

<div class="post-metadata">

**Author:** ![Heoki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Heoki](https://forums.unrealengine.com/u/Heoki)\
**Post date:** [December 26, 2015, 5:11pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/87 "2015-12-26T17:11:44Z")

</div>

> [@;442573](#):
>
> One more question.  
> How to make individual sight range for different units in one team?

I’m able to get it to work with multiple team based actors by selectively registering them with the FogOfWarManager. To get individual radius, inside of FogOfWarWorker I added the code below to the UpdateFowTexture() method which may not be the most efficient way but it works.

```auto

	for (auto Itr(Manager->FowActors.CreateIterator()); Itr; Itr++) {
		//Find actor position
		if(!*Itr) return;		
		FVector position = (*Itr)->GetActorLocation();

		// ----- START NEW CODE -----
		// Use sight radius from character attribute.
		ABaseCharacter* character = Cast<BaseCharacter>(*Itr);
		if (character)
		{
			sightTexels = (character->SightRadius / 100) * Manager->SamplesPerMeter; //Sight radius is in centimeters on character and the fow worker sightTexels expects meters.
		}
		// ----- END NEW CODE -----
...

```

---

<div class="post-metadata">

**Author:** ![Heoki](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Heoki](https://forums.unrealengine.com/u/Heoki)\
**Post date:** [December 26, 2015, 5:17pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/88 "2015-12-26T17:17:34Z")

</div>

> [@Maxpower13;443301](#):
>
> Hi, This is my first time using C++ instead of blueprints so I am getting quite stuck :(. I am getting various errors when compiling the code such as “use of undefined type 'AFogOfWarManager” for example, I think it may be due to not changing the correct things in the code or not adding needed things. As I have simply copied and pasted the code it would be really helpful to know exactly what needs to be changed to make it compile smoothly.  
> Any help would be greatly appreciated.

You might need to include FogOfWarManager.h in the FogOfWarWorker.cpp since the set up in the first post expects it to be set up in your main project header I believe.

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [December 27, 2015, 11:46am UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/89 "2015-12-27T11:46:42Z")

</div>

Oh, thanks for answer, but i already did individual sight myself 😃  
Im a coder, but new to c++. The only one problem i still have, as someone in this topic, black square if fog of war isnt black (because i need map to be ‘discovered’) and if i use blur =S

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [December 27, 2015, 12:11pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/90 "2015-12-27T12:11:52Z")

</div>

As i see, this black strange thing only appearce in vertical blur, so need to look vertical blur code…

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [December 27, 2015, 1:14pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/91 "2015-12-27T13:14:33Z")

</div>

I didnt want to explore all code of bluring, cause im really new to c++, so i just added

```auto

		if (sum < 100){
				sum = 100;
			}

```

after vertical blur code, so he looks now this way

```auto

		//Vertical blur pass
		for (auto Itr(texelsToBlur.CreateIterator()); Itr; ++Itr) {
			int x = (Itr)->IntPoint().X;
			int y = (Itr)->IntPoint().Y;
			float sum = 0;
			for (int i = 0; i < Manager->blurKernelSize; i++) {
				int shiftedIndex = i - offset;
				if (y + shiftedIndex >= 0 && y + shiftedIndex <= signedSize - 1) {
					sum += (Manager->blurKernel* * Manager->HorizontalBlurData[x + (y + shiftedIndex) * signedSize]);
				}
			}
			if (sum < 100){
				sum = 100;
			}
			Manager->TextureData[x + y * signedSize] = FColor((uint8)sum, (uint8)sum, (uint8)sum, 255);
		}

```

and this vertical bug got fixed.  
Hope it helps for anybody

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [January 11, 2016, 7:18pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/92 "2016-01-11T19:18:00Z")

</div>

- THANK YOU for sharing this! In addition to FoW your tutorial helped me learn dynamic texture creation and multi-threading in a practical manner as well.

I used this FoW setup last year and had this thread bookmarked for replying but never got to it until now - I thought better late than never to drop by 🙂

For people experiencing intermittent crashing - I found overriding EndPlay like this helped:

```auto

void AFogOfWarManager::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	FowActors.Empty();

	if (FowThread) {
		**FowThread->ShutDown();**
	}

}

```

I’m not using Fog Of War anymore (game no longer an RTS), but in any case - 's tutorial was a lifesaver when I really needed it, so thank you!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_02adf4fd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_02adf4fd](https://forums.unrealengine.com/u/anonymous_user_02adf4fd)\
**Post date:** [January 12, 2016, 7:26am UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/93 "2016-01-12T07:26:34Z")

</div>

> [@;452021](#):
>
> - THANK YOU for sharing this! In addition to FoW your tutorial helped me learn dynamic texture creation and multi-threading in a practical manner as well.
> 
> I used this FoW setup last year and had this thread bookmarked for replying but never got to it until now - I thought better late than never to drop by 🙂
> 
> For people experiencing intermittent crashing - I found overriding EndPlay like this helped:
> 
> ```auto
> 
> void AFogOfWarManager::EndPlay(const EEndPlayReason::Type EndPlayReason)
> {
> FowActors.Empty();
> 
> if (FowThread) {
> **FowThread->ShutDown();**
> }
> 
> }
> 
> ```
> 
> I’m not using Fog Of War anymore (game no longer an RTS), but in any case - 's tutorial was a lifesaver when I really needed it, so thank you!

Hey man, that’s super nice of you to give thanks. As for multi-threading and dynamic texture creation in UE4, I learned both topics from tutorials so he should get at least 85% of the gratitude 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_10f3a621](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_10f3a621](https://forums.unrealengine.com/u/anonymous_user_10f3a621)\
**Post date:** [January 20, 2016, 9:26pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/94 "2016-01-20T21:26:18Z")

</div>

I have converted this to 4.10 and it is compiling, but I cannot add the SceneTexture:PostProcessInput0 node to the material. It just does not show up as an option. Any ideas what I’m missing?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_02adf4fd](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_02adf4fd](https://forums.unrealengine.com/u/anonymous_user_02adf4fd)\
**Post date:** [January 20, 2016, 9:39pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/95 "2016-01-20T21:39:22Z")

</div>

> [@](#):
>
> I have converted this to 4.10 and it is compiling, but I cannot add the SceneTexture:PostProcessInput0 node to the material. It just does not show up as an option. Any ideas what I’m missing?

Hi ,

I think you’d be able to add the node using these steps:

1. Open you material.
2. Select the material return node or don’t select any node at all. In the details panel under Material, change “Material Domain” from Surface to Post Process.
3. Right click on the material black board and search for “SceneTexture”-node. Add the node.
4. Select the node. In the details panel change “SceneTextureId” from SceneColor to PostProcessInput0.

Cheers,

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_10f3a621](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_10f3a621](https://forums.unrealengine.com/u/anonymous_user_10f3a621)\
**Post date:** [January 20, 2016, 10:12pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/96 "2016-01-20T22:12:52Z")

</div>

Got it Thanks!! It was hiding in that pesky details panel. It is working correctly now thank you.

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [January 29, 2016, 1:03pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/97 "2016-01-29T13:03:22Z")

</div>

Hello! I got strange problem, FOW dont work in packaged game… Do u have any ideas?

---

<div class="post-metadata">

**Author:** ![Alexarg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alexarg](https://forums.unrealengine.com/u/Alexarg)\
**Post date:** [January 29, 2016, 2:26pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/98 "2016-01-29T14:26:39Z")

</div>

@anonymous_user_964c5f2d thanks for this, this is very helpful and well explained.  
A question, I am having some heavy fps oscillation, that cause i believe, a noticeable stuttering.  
Are any of you having this kind of effect? It is expectable? My rig is pretty good. I’m using w10, so maybe could be related to that.

Thanks again!!

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [January 29, 2016, 2:33pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/99 "2016-01-29T14:33:38Z")

</div>

Also, FOW not working in network game, its always black =c

---

<div class="post-metadata">

**Author:** ![stunder](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@stunder](https://forums.unrealengine.com/u/stunder)\
**Post date:** [January 29, 2016, 2:39pm UTC](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222/100 "2016-01-29T14:39:05Z")

</div>

Guys, who used fog in network game?  
I dont really understand, why it dont work…

[Previous page](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222.md?page=4)

[Next page](https://forums.unrealengine.com/t/tutorial-fog-of-war/18222.md?page=6)
