fog not the same color in build??

Hi,

I’m changing the fog color and density via script, depending on what level the user chooses to play like so:

    public Color color = new Color();
    public Color color2 = new Color();
    public Color color3 = new Color();
    public Color color4 = new Color();




    void Awake()
    {
    

        RenderSettings.fogDensity = 0.01F;
        CapsuleCollider cCollider = GetComponent<CapsuleCollider>();

        Scene currentScene = SceneManager.GetActiveScene();

        string sceneName = currentScene.name;

        if (sceneName == "lvl1")
        {
            Cursor.visible = false;
            RenderSettings.fogColor = color;
            RenderSettings.fogDensity = 0.02F;
        }
        if (sceneName == "lvl2")
        {
            Cursor.visible = false;
            RenderSettings.fogColor = color2;
            RenderSettings.fogDensity = 0.02F;
        }
        if (sceneName == "lvl3")
        {
            Cursor.visible = false;
            RenderSettings.fogColor = color3;
            RenderSettings.fogDensity = 0.02F;
        }
        if (sceneName == "lvl4")
        {
            Cursor.visible = false;
            RenderSettings.fogColor = color4;
            RenderSettings.fogDensity = 0.015F;
        }

The colors are defined in the inspector and they seem to work on all levels except level 3. “lvl3” has the same as lvl 1 even though it should be a totally different color. The logical problem could be that level 3 isn’t name lvl3 but it is… I haven’t been able to find any information about the problem online, does anyone know why this is happening?

It works as it should in the inspector, its only in the build that lvl3 has the wrong color. it makes no sense :confused:

If you’re using colors you are providing in the inspector, why are you writing “= new Color()” for each one?

Add the following line as line 19 to verify the scene name. Make sure in the console output it exactly matches the text you’re using in your “if” statements.

Debug.Log("sceneName: " + sceneName);

I’d also try changing your Color declarations to this:

public Color color;
public Color color2;
public Color color3;
public Color color4;

I wrote it like I did because, before deleting the numbers, I tried defining the colors : public Color color4 = new Color(55f,255f,0f,255f); for example.

But neither that nor your suggestion makes any difference since the problem isn’t happening in the editor, only when I make a build…

Debugging the scene name proved that the correct scene is being loaded but the fog still isn’t the correct color when I make a build. In play mode in the editor it’s exactly how it should be…