Fog Problems in Build

I have a set up where the default fog mode is linear. Upon pressing a button, the fog mode goes to exponential with a density of 0.02. If you press the button again, it goes back to linear.

This works great in the editor.

In the builds it does not work. The linear works fine, but when I try to turn on the exponential, all fog disappears entirely. No exponential. If I turn it back to linear, linear works again. Only the exponential fails in this case, but works in the editor.

Now, if I set exponential to the default and never set it to linear in the build, then the exponential shows up just fine.

Seems it only happens when going from linear to exponential. Any idea what would cause this? Is it a Unity bug I should report?

Thanks.

Edit: Using Unity 5.2.1.

Does sound strange, can you put together a little example scene and report it as a bug?

I’ve sent a bug report.

1 Like

Turns out this wasn’t a bug - I just needed to specify the fog modes that Unity needed to use via Project Settings → Graphics → Fog Modes. This is true only if setting via script.

I had no idea.

2 Likes

I did not know you needed to do that.

Thanks Jason. That works. I set mine to only use Exponential. I use a script and rendersettings to tune my fog. works well now. Cheers.
Example:
using UnityEngine;
using System.Collections;

public class myFog : MonoBehaviour
{
float fogDensity = 0.01f;
// Use this for initialization
void Start ()
{

RenderSettings.fogColor = Camera.main.backgroundColor;
RenderSettings.fogDensity = fogDensity;
RenderSettings.fog = true;

}

void FixedUpdate()
{
fogDensity = Random.Range (0.01f,0.02f);
//Debug.Log(fogDensity);
}

}