Search Unity

How to change lightmap in runtime on mobile

Discussion in 'Global Illumination' started by doctorgusakov, Aug 9, 2019.

  1. doctorgusakov

    doctorgusakov

    Joined:
    Apr 10, 2019
    Posts:
    3
    Hello! Guys, can anyone tell me how to switch to pre-baked lighting maps on mobile on runtime? This code works fine in the editor, but when launched on mobile - lightmaps simply do not work. :(

    Code (CSharp):
    1.  public Texture2D firstMapDir;
    2.     public Texture2D firstMapColor;
    3.     public Texture2D secondMapDir;
    4.     public Texture2D secondMapColor;
    5.  
    6.     private LightmapData[] firstLightMaps = new LightmapData[1];
    7.     private LightmapData[] secondLightMaps = new LightmapData[1];
    8.  
    9.     void Start()
    10.     {
    11.         firstLightMaps[0] = new LightmapData();
    12.         firstLightMaps[0].lightmapDir = firstMapDir;
    13.         firstLightMaps[0].lightmapColor = firstMapColor;
    14.  
    15.         secondLightMaps[0] = new LightmapData();
    16.         secondLightMaps[0].lightmapDir = secondMapDir;
    17.         secondLightMaps[0].lightmapColor = secondMapColor;
    18.  
    19.     }
    20.  
    21.     public void SetToFirstLightmap()
    22.     {
    23.         LightmapSettings.lightmaps = firstLightMaps;
    24.     }
    25.  
    26.     public void SetToSecondLightmap()
    27.     {
    28.         LightmapSettings.lightmaps = secondLightMaps;
    29.     }
     
  2. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    I can't see how this could even work in the Editor, as the four textures in the beginning of the script are never assigned any value.
     
  3. JenniferNordwall

    JenniferNordwall

    Unity Technologies

    Joined:
    Sep 19, 2016
    Posts:
    160
    Hi! It feels like a big part of the setup and script is missing, would you mind sharing it with us? Also show us your current settings setup and what version of Unity you are using, and in what way it doesn't work :)

    Cheers!