Search Unity

Question Lightmap in prefabs ?

Discussion in 'Editor & General Support' started by barka, Jun 30, 2022.

  1. barka

    barka

    Joined:
    Oct 17, 2015
    Posts:
    1
    Is there any way to store lightmaps with prefabs , I did one solution with shader graph to include lightmap in uv2 and adjust the coordinates with this script
    Code (CSharp):
    1. Mesh meshToModify = GetComponent<MeshFilter>().sharedMesh;
    2. Vector4 lightmapOffsetAndScale = GetComponent<Renderer>().lightmapScaleOffset;
    3.  
    4. Vector2[] modifiedUV2s = meshToModify.uv2;
    5. for (int i = 0; i < meshToModify.uv2.Length; i++)
    6. {
    7.     modifiedUV2s[i] = new Vector2(meshToModify.uv2[i].x * lightmapOffsetAndScale.x +
    8.     lightmapOffsetAndScale.z, meshToModify.uv2[i].y * lightmapOffsetAndScale.y +
    9.     lightmapOffsetAndScale.w);
    10. }
    11. meshToModify.uv2 = modifiedUV2s;
    But I am facing another issue after building the uv map returns to default values