Ayfel / PrefabLightmapping

Script for saving lightmapping data to prefabs. Used through the Assets tab in Unity. Place your prefbas in the scene with this script at the root. Set up your lighting and in the editor go to Assets->Bake Prefab Lightmaps. After is processed you can now spawn your prefabs in different scenes and they will use the lightmapping from the original scene.
645 stars 90 forks source link

Incorrect light maps being assigned on instantiation #67

Open MarcJamesIO opened 6 months ago

MarcJamesIO commented 6 months ago

This script no longer works, unfortunately - when dynamically instantiating light-mapped prefabs using the method in the ReadMe, the incorrect lightmap is sometimes assigned to the prefab (with the incorrect lightmap index.)

image

The two lighter corridors are dragged from the project explorer into the scene with correct lightmaps. The two darker corridors are the same prefab and are instantiated at runtime. They have the incorrect lightmap attached to them.

The correct prefab lightmap:

image

The instantiated at runtime lightmap:

image

Unity 2022.3.9f URP

Ayfel commented 6 months ago

You probably rebaked in the scene where your prefab is and the script has the old index (so there is a mismatch). The script works just fine for me. Try using the bake method from the Menu again(Assets->Bake Prefab Lightmaps) again. Once its done you can check in the scripts what is saved to it to confirm (the fields in the script are public so you can inspect them)

MarcJamesIO commented 6 months ago

Ok will take a look. A secondary problem is that when the prefab is rotated 180 degrees, the lightmap darkens? I've got 0 lighting in the scene (everything set to black) but when a light-mapped baked prefab rotates the textures darken anyway?

image