Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Assign lightmapIndex and lightmapScaleOffset doesn't work in unity5.0.0f4

Discussion in 'Global Illumination' started by xiewneqi, Apr 30, 2015.

  1. xiewneqi


    Aug 20, 2012
    Hi, I'm working on a endless runner game now. To achieve lightmap effect in a runtime generated scene with runtime generated objects, I build my lightmap textures of all essential prefabs before in editor and assign lightmapData using following code in runtime:
    Code (CSharp):
    1. Texture2D lightmapTexture = Resources.Load<Texture2D> ("myLightmapTexturePath");
    2. if (lightmapTexture != null)
    3. {
    4.     LightmapData data = new LightmapData ();
    5.     data.lightmapFar = lightmapTexture;
    6.     LightmapSettings.lightmaps = new LightmapData[]{data};
    7. }
    And for every instantiated instance of prefab, lightmapIndex and lightmapScaleOffset are assigned usingfollowing code:
    Code (CSharp):
    1. MeshRenderer meshRenderer = gameObject.GetComponent<MeshRenderer> ();
    2. meshRenderer.lightmapIndex = _lightmapIndex;
    3. meshRenderer.lightmapScaleOffset = _lightmapScaleOffset;
    where _lightmapIndex and _lightmapScaleOffset are recorded in a script along with MeshRenderer Component when lightmapping baking is finished in editor.
    After these steps, the lightmap texture appears in Lighting/Lightmaps window correctly, and every meshrender reports the correct lightmapIndex and lightmapScaleOffset.
    However, no lightmap effect shows in the scene, while in Unity 4.3 every thing works fine, so is there any problem with my approach in Unity5.0.0.f4?