Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Baked lightmaps broken in mobile

Discussion in 'General Graphics' started by kk3hi3123, Dec 14, 2019.

  1. kk3hi3123

    kk3hi3123

    Joined:
    Aug 17, 2016
    Posts:
    31
    I am making a game with different levels. Each level is an additive scene having 2 sets of lightmaps, Day version and Night version. LightmapSettings will be updated after the scene is loaded.

    Code (CSharp):
    1. [System.Serializable]
    2. public class LightmapTextures
    3. {
    4.     public Texture2D[] lights;
    5.     public Texture2D[] dirs;
    6.     public Texture2D[] shadows;
    7. }
    8.  
    9. public class LightmapSwitch : MonoBehaviour
    10. {
    11.    
    12.     public LightmapTextures[] lightmaps;
    13.  
    14.     public void SetLightMap(int index)
    15.     {
    16.         LightmapTextures lightmapTextures = lightmaps[1 - index];   // Setting mistake
    17.         LightmapData[] lightmapData = new LightmapData[lightmapTextures.lights.Length];
    18.  
    19.         for(int i = 0; i < lightmapTextures.lights.Length; i++)
    20.         {
    21.             lightmapData[i] = new LightmapData();
    22.             lightmapData[i].lightmapColor = lightmapTextures.lights[i];
    23.             lightmapData[i].lightmapDir = lightmapTextures.dirs[i];
    24.             if (i < lightmapTextures.shadows.Length)
    25.             {
    26.                 lightmapData[i].shadowMask = lightmapTextures.shadows[i];
    27.             }
    28.            
    29.         }
    30.        
    31.         LightmapSettings.lightmaps = lightmapData;
    32.     }
    33. }
    It works fine in the editor. When I build on Android, the lightmaps looks well in the beginning. But after some levels, the lightmaps will be broken until I restart the app.

    Screenshot 2019-12-15 at 2.40.37 AM.png

    Is there any setting mistake from my codes or my maps? Or is it caused by caching or out of memories?
     
  2. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,074
    @kk3hi3123

    Interestingly, this problem happens on Unreal Engine, and other game engines too, when you put/build game that has lightmaps, onto mobile. The fact that this problem occurs on other game engines is interesting, and shows this is not just a Unity game engine problem.

    Okay. Change or toy around with the compression settings, and see if that works.


    Strangely enough, I always had a suspicion, that this might be, some sort of mobile gpu rendering, gpu memory, or RAM bug.:confused:
     
    Last edited: Jul 28, 2020