PrefabLightmapping icon indicating copy to clipboard operation
PrefabLightmapping copied to clipboard

Lightmap working fine first time, but not applying on subsequent

Open LethalHonor opened this issue 3 years ago • 3 comments

Hello there.

I have a problem with baking a prefab and I don't know how to proceed.

I have added the script to a prefab with some models and terrains. When the baking process is over, you can see the effect on the terrain: the objects cast shadows in the terrain.

LHE - 01 - Baked shadows work perfectly

But if I remove the prefab from the scene and add it again, it should show the same lightmapping as before, but in this case, they are removed: LHE - 02 - Removed and added again - Not showing baked shadows

If I play the game and instantiate that prefab in another scene (the purpose of the asset), the shadows are gone too. LHE - 03 - Instantiated in realtime in another scene - Not showing baked shadows

What am I doing wrong? Thanks a lot for your time!!!

LethalHonor avatar Jul 19 '21 08:07 LethalHonor

Does it bake other shadows? I see some shadows in that asset and some others that are missing. What are your lighting settings?

Ayfel avatar Jul 19 '21 14:07 Ayfel

Hello there!

Not, it doesn't bake any shadows at all. The shadows you see are black sprites we use to simulate shadows. For example, this is the scene with no light baking: LHE - 04 - Black sprites shadows - No baked

This is after Asset - Bake prefab lightmap: LHE - 04-2 - Baked map

Then, if I remove the prefab from the scene and add it again, it should reload the lightmap info from the script but... it doesn't. LHE - 04-3 - Removed and added again - Not baked lights

The PrefabLightmapData script in the prefab is filled and fine, but It seems not to apply the lightmap info when added to the scene or instantiated in-game: LHE - 04-4 - The info is fine

  • This is the lighting settings: LHE - 05 - Lighting settings

More info:

  • I have one specific scene for that prefab (called Lightmap_Combat_VS_02A)
  • The prefab is a GameObject with the PrefabLightmapData at its root.
  • There is only one directional light, static and set to mixed. There are other lights, also set to mixed.
  • All 3d elements are static and contribute to GI.

Additional info for other scenes:

In other scenes, the lightmap script works for some lights, but it doesn't work (all lights are set exactly the same). Or maybe the problem is a misplacement?

For example: For an indoors scene If I bake the lights, I get this result: LHE - 06 - Closed scene - Baked light

But when I remove the prefab and add it again to the same scene (or instantiate in-game in real-time), I see this: LHE - 06 - Closed scene - Removed and then deleted - Not working some lights

It looks like it has something to do with not getting the information right when it comes to loading the lightmap info...

These are the lighting settings for this scene: LHE - 07 - Indoors scene - Lighting settings

Any ideas on how to proceed??

Thanks a lot!

LethalHonor avatar Jul 20 '21 10:07 LethalHonor

First I recommend including the light in the prefab, just in case you don't already as the script should keep track of the lights in order to apply the mixed ones in the proper way. This is an issue of mixed lights mainly. Let me know if that solves your issue, otherwise we can look at it in a bit more detail and try to replicate the issue.

Another question for reference, what renderer pipeline are you using?

Ayfel avatar Jul 20 '21 14:07 Ayfel