Search Unity

Light gone ?

Discussion in 'Getting Started' started by Quast, May 23, 2016.

  1. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    I'm using unity version 5.3.5.
    why if i load scene (using code) the light gone ?
     
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    The puck has a shadow so you do have a directional light. I don't know what your question is.
     
  3. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    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?
     
  4. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    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 ?
     
  5. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    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.
     
  6. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    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.
     
  7. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    here is my code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class loadscene: MonoBehaviour {
    6.  
    7.     public string mylevel;
    8.     void Start()
    9.     {
    10.         mylevel = SceneManager.GetActiveScene().name;
    11.     }
    12.  
    13.     void save()
    14.     {
    15.         PlayerPrefs.SetString("sss",mylevel);
    16.         Debug.Log("save");
    17.     }
    18.  
    19.     void load()
    20.     {
    21.         SceneManager.LoadScene(PlayerPrefs.GetString("sss")); // this line load my scene.
    22.         Debug.Log("load");
    23.     }
    24. }
    25.  
    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).
     
  8. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    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.
     
    rapidrunner likes this.
  9. Quast

    Quast

    Joined:
    Jul 5, 2015
    Posts:
    560
    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
     
  10. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289
    I am seeing what you are describing, and I made a video of the issue:



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

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class loadscene: MonoBehaviour {
    6.  
    7.     static bool didWeReload = false;
    8.     public string mylevel;
    9.  
    10.     void Start()
    11.     {
    12.         mylevel = SceneManager.GetActiveScene().name;
    13.     }
    14.  
    15.  
    16.     void Update()
    17.     {
    18.         if (Time.time > 10.0f && !didWeReload) {
    19.             didWeReload = true;
    20.             Debug.Log ("save and load");
    21.             save ();
    22.             load ();
    23.         }
    24.  
    25.     }
    26.  
    27.  
    28.  
    29.     void save()
    30.     {
    31.         PlayerPrefs.SetString("sss",mylevel);
    32.         Debug.Log("save");
    33.     }
    34.  
    35.     void load()
    36.     {
    37.         SceneManager.LoadScene(PlayerPrefs.GetString("sss")); // this line load my scene.
    38.         Debug.Log("load");
    39.     }
    40. }
    I tried running it in a Build, and I did not see the issue in a build.

    Thanks.
     
    rapidrunner likes this.
  11. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    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.
     
  12. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    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.
     
    rapidrunner and tedthebug like this.
  13. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    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.