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.
618 stars 88 forks source link

Can't get baked lighting to work in a cloned prefab object #44

Open hookmanuk opened 2 years ago

hookmanuk commented 2 years ago

Hi there,

I have quite a simple set up, one prefab with one area light in it and some other prefabs inside it.

image

I've run the Assets->Bake Prefab Lightmaps, which generated the lightmaps on the right, which seems fine.

When I run my code, I'm instantiating a clone of RoomMedium1 next to it, but no lightmaps are applied to it

image

What am I doing wrong? Is there a working example anywhere I can use as a guide?

hookmanuk commented 2 years ago

Also note, if I add a new "RoomMedium" prefab object in design time, it also looks like this, I'm unsure whether it is supposed to apply the light maps in design or runtime, but its doing neither at the moment.

Ayfel commented 2 years ago

This is most likely because of nested prefabs, try to only have a top root prefab to test it, no inside prefabs

hookmanuk commented 2 years ago

Thanks for the reply. I've created a new URP project for 2020.3.7f1 to test this in isolation. I've published it here, could you take a look and see what I've done wrong, I assume its something pretty obvious! The cloner object/script creates an instance of the prefab, but no lightmaps are applied.

https://github.com/hookmanuk/prefablightmappingtest

Ayfel commented 2 years ago

Great, I am currently on a trip and wont be able to check it until bavk, if you haven't found the reason these days(i think if you unlink the nested prefabs it should work), then remind me next week from Wednesday when I am back and I will take a look

hookmanuk commented 2 years ago

OK thanks, my example doesn't have nested prefabs now, just a couple of cubes and an area light, so I don't think it's that.

hookmanuk commented 2 years ago

Thinking about it some more, I'm generating new connected rooms to walk through as the player progresses. I can probably just have 3 rooms prebaked and just move them around instead, that should get around the issue and probably be better for performance anyway.

Thanks for trying to help, let me know if you do find the issue with the sample anyway.