Light gone ?

I’m using unity version 5.3.5.
why if i load scene (using code) the light gone ?

The puck has a shadow so you do have a directional light. I don’t know what your question is.

As pointed out, you have shadows on the puck and the sphere on the purple area; so there is lighting.

Are you referring to the wrong shader that is displayed in pink?

the above image is about a scene i load it by using code it appear like no light “dark”.
But if i open the same scene it appear like this:

where is the problem ?

show us your code (using the code tags to put it up properly formatted) & a screenshot of what it looks like loaded.

I have had an issue where the image had no light when running it through the editor but it works fine when I do a build & then play it from there.

Also would help to understand if you are opening in the editor or in the standalone executable that you build.

It is quite hard to even understand the problem, without a clear description of what you get and what you expect.

If you are posting a screenshot that does not have the issue; it is not helping to figure out what the issue is.

here is my code:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class loadscene: MonoBehaviour {
  
    public string mylevel;
    void Start()
    {
        mylevel = SceneManager.GetActiveScene().name;
    }

    void save()
    {
        PlayerPrefs.SetString("sss",mylevel);
        Debug.Log("save");
    }

    void load()
    {
        SceneManager.LoadScene(PlayerPrefs.GetString("sss")); // this line load my scene.
        Debug.Log("load");
    }
}

I think its a bug.

Really ! in both images no difference ? Can’t you see the interface of the engine ? How to explain something that is clear i don’t understand it ? I give you information, images and now code. //If you are posting a screenshot that does not have the issue// no issue !!!
Scene in my game if i open it ((Double click on the scene icon)) open normal without any issue (image number 2).
If i use code to open the same scene ((press a button to load that same scene)) it open a lite bit darker like no light there (Image number 1).

One is darker than the other but they both have shadows showing that you do have a directional light in both scenes. The problem is linked to you running it in the editor, if you do a build you won’t see the ‘problem’. I say ‘problem’ because it is just a display issue, there is no real problem because you do have a light & it is casting shadows.

1 Like

So, Its bug ! silly bug.
Unity developments community can’t fix it ?
I tried the same thing with version 5.3.3 and got the same result !!
Thank you ted

I am seeing what you are describing, and I made a video of the issue:

https://www.youtube.com/watch?v=zktnBzadr1I

I wrote some code to reload after 10 seconds. Here it is with your code:

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class loadscene: MonoBehaviour {
  
    static bool didWeReload = false;
    public string mylevel;

    void Start()
    {
        mylevel = SceneManager.GetActiveScene().name;
    }


    void Update()
    {
        if (Time.time > 10.0f && !didWeReload) {
            didWeReload = true;
            Debug.Log ("save and load");
            save ();
            load ();
        }

    }



    void save()
    {
        PlayerPrefs.SetString("sss",mylevel);
        Debug.Log("save");
    }

    void load()
    {
        SceneManager.LoadScene(PlayerPrefs.GetString("sss")); // this line load my scene.
        Debug.Log("load");
    }
}

I tried running it in a Build, and I did not see the issue in a build.

Thanks.

1 Like

No light = absence of light = can’t see anything. This is why I was asking for more details.
a little bit darker != no light

IF you are using by any chance precalculate and baked GI ; there is a long time standing issue filed against the editor. From the first build of Unity 5 I believe.

If your scene is bright when manually opened in the editor, but darker when loaded from code, that’s because the global illumination isn’t calculated when loaded from code. The dynamic lights within the scene keep working (eg. the light casting shadows) but the overall brightness of the scene is low because it’s not being brightened by GI.

The way to fix it is to bake the lighting, so that it doesn’t have to be calculated on the fly. Go to Window > Lighting and scroll down to Build at the bottom. This issue is unexpected enough (eg. it caught me off guard at first) that they might want to warn about it within Unity.

2 Likes

Actually I use pre-calculated GI, but not baked, and I do not see the issue. My scene load from code without issues.

I get the issue only if I use baked + realtime GI. I have set the lighting to manual; so when I make changes I have to bake again for reatlime GI, but it takes a snap, so no big deal.

Also if you use mixed for the lights; it works fine; I didn’t try with realtime or baked only.