Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baked lighting is broken upon instantiating from Asset Bundle #57

Open
MichaelBezzina opened this issue Oct 24, 2022 · 25 comments
Open

Comments

@MichaelBezzina
Copy link

temp_LightingIssue-Working
temp_LightingIssue-NotWorking

Hi there, I first wanted to start off by thanking you for making this resource available as it proves to be a powerful solution for a lot of us!
My issue appears in the process of instantiating a prefab with this baked lighting via an Asset Bundle. There are a few things I've tested that are listed out below:

  • If I load a scene via an Asset Bundle with the prefab already instantiated inside of it, then the lighting will look correct (although I am seeing that the prefab will lose its static tag).
  • If I load the prefab into a scene via a reference to it within the project, the lighting will look correct.
  • I have completely unloaded all prefabs nested within the prefab with the broken lighting.
  • I have tried making it Static, Not Static, and Static but with the Static Batching unchecked. None of these have resolved the issue when it's loaded in via Asset Bundle (seems to lose the static tag regardless).

Thanks in advance

@Ayfel
Copy link
Owner

Ayfel commented Oct 24, 2022

Ok so, I don't understand exactly when the issue arises? Is it only when instantiated on its own as a GameObject? Can you share the code for how you load it vs for how you load it when it works?

-"If I load a scene via an Asset Bundle with the prefab already instantiated inside of it, then the lighting will look correct (although I am seeing that the prefab will lose its static tag)." < This is normal, its the way it works for instantiating scenes through bundles but it still behaves as static (having combined meshes etc)

Is the project where you use the Asset bundle the same as where you make the assetbundle?

Also can you share some info on Unity version, Render pipeline, etc

@MichaelBezzina
Copy link
Author

Hi, thanks for the quick reply. I'm running this on 2019.4.26f1 with URP.
As for how I'm using the prefabs with the baked lighting... I currently have an initialization scene with nothing but a loader script which takes a scene from an Asset Bundle and loads that scene. From there, that loaded scene then asks for prefabs from another Asset Bundle to be instantiated. I want to move my prefabs with the baked lighting out of the scene being loaded in (which currently shows the baked lighting correctly) and into the Asset Bundle which the scene grabs prefabs from instead (which does not work and results in what you see above).

@Ayfel
Copy link
Owner

Ayfel commented Oct 24, 2022

Can you make sure that the other assetbundle you have your prefabs in contains all the lightmap textures? Also can you see in the hierarchy if those are properly assigned in the script?

@MichaelBezzina
Copy link
Author

temp_LightingIssue-FollowUp02
temp_LightingIssue-FollowUp

I made sure to include the lightmap textures and the LightingData.asset file in the Asset Bundle and ran it again, but see the same issue.
It seems like they may not be properly assigned. In the lighting scene I have which bakes the prefabs, I see the Baked Lightmap on the mesh, but then during runtime, I don't see the Baked Lightmap show up on that same mesh (images included). Anything else I can look for to find discrepancies?

@Ayfel
Copy link
Owner

Ayfel commented Oct 24, 2022

Can you check the top of the prefab, the object/script PrefabLightmapData.cs? that's where the lightmaps are "stored"

@MichaelBezzina
Copy link
Author

MichaelBezzina commented Oct 24, 2022

temp_LightingIssue-FollowUp03

Let me know if I should be looking at any of these dropdowns specifically. I see 185 items under Renderer Info (with valid mesh references), 20 Lightmaps (with seemingly valid entries), 20 Lightmap Dir (all labeled as null), 20 Shadow Masks (all labeled as null), and 10 items under Light Info (with valid references)

@Ayfel
Copy link
Owner

Ayfel commented Oct 24, 2022

Ok thank you, everything seems fine, would it be possible for you to make a repo project for me? And empty project with two bundles (scene one with a baked prefab in it) and a bundle of the prefab, with a couple of scenes mimicking your load method. That way I can go in and debug it and figure out the issue for you and see where its failing to load the lightmaps

@MichaelBezzina
Copy link
Author

Sure, I'll try to get that out to you sometime today. I appreciate your help

@MichaelBezzina
Copy link
Author

Okay, got a repo setup. Let me know if this works for you
https://github.com/MichaelBezzina/ExampleProject_LightingIssue

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

Thank you, I am not getting anything loaded with the bool set to false
image

Let me know if I am missing something

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

I'll keep checking tomorrow, but another thing I noticed is that if I try (in the editor) to select anything in that instantiated prefab and set it to static then Unity crashes
image

@MichaelBezzina
Copy link
Author

Sorry, I shouldn't have made that bool toggleable with this demo. You can leave that set to true, because that is how it is being used in this context.
As for the crash, I'm also experiencing that not only in this demo, but in my main project as well. Not sure if that's related to the lighting issue, or simply something you are unable to do during runtime.

@MichaelBezzina
Copy link
Author

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

Thanks, could you also include the prefab in your repo project? That way I can compare the instantiated one from the bundle and the regular one when debugging (need to check if the lightmap is applied at the right coordinates, or if its a shader issue, etc)

@MichaelBezzina
Copy link
Author

Working on adding those now. Got a lot of random stuff being exported with the prefabs from my main project so I'm working on cleaning that up as I bring them over into this demo repo

@MichaelBezzina
Copy link
Author

Okay, well, I got the prefabs added to the project and only stripped out the people to reduce the amount of assets that needed to be exported over. The asset bundles currently included in this project are still from the main project though because the process of trying to bake these prefabs in this demo is causing Unity to max out the memory for some reason so I'm unable to make asset bundles based on this repo.
And to be clear, if I move the prefab in its own asset bundle into the asset bundle with just the scene, the baked lighting will work perfectly fine. Hopefully these are somewhat helpful in the debugging process though (both located in 'Assets\Prefabs\AssetBundlePrefabs\SpawnableObjects\EnterAndExplore')

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

Ok so the issue I have is that I cannot compare because the prefab you included doesn't have the same references to lightmaps
image
there are no lightmaps for me to compare and check against. I was hoping to be able to drag and drop the "Apartment" into the scene to compare.

So if I understand correctly the issue happens only when the prefab is part of the assetbundle of the scene? Or am I understanding this in a different way?

  1. Assetbundle A contains scene AND prefab - It doesn't work

  2. Assetbundle A (scene), AssetBundle B (prefab)- It works

Can you add a scene that does the case where you say its correct (what you mention of its own assetbundle), so I can compare both. With only the non-functioning case I am a bit blind on to what is happening.

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

Ok, looking at the code. It is the other way around. It is when its in its own assetbundle that the prefab is not being lit up. Does the "examplebundle" only contain the apartment or does it contain the other as well? (just trying to figure out how to get the same prefab to work and not work so I can compare)

@MichaelBezzina
Copy link
Author

It's moreso this:

  • If you put the baked prefab into a scene, set the scene to be included in an asset bundle, and then grab and instantiate that scene from that asset bundle during runtime - It Works
  • If you put that prefab directly in an asset bundle and then try to grab and instantiate that prefab during runtime - It does not work

I was hoping that I could bake the prefabs in the Lighting_Scene that I created within this demo project in order to create those references for you, but when I try to bake them in this project, my Unity Editor gets stuck and uses a bunch of memory during that process. I'll try to get that fixed tonight or tomorrow so that you can properly check those references. I can also provide some screenshots from the main project we have since there seems to be some issues with this demo project at the moment.

@MichaelBezzina
Copy link
Author

MichaelBezzina commented Oct 25, 2022

In this demo repo, the examplebundle contains only the apartment. In the main project, however, it contains a bunch of other stuff as well

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

Ok I am pretty sure its this same issue here:

    "Further exploration seems to show that the meshes are being stored without the UV1 information (which is used for lightmaps), I need to look to see if there is a way to force that being stored when exporting the bundles. I'll let you know if I find out.

I believe its the way URP exports that it leaves the UV1 of meshes off the assetbundle for some reason

Originally posted by @Ayfel in #53 (comment)

"

@Ayfel
Copy link
Owner

Ayfel commented Oct 25, 2022

So this is a Unity bug that needs to be reported to Unity, hopefully they will fix it (or have fixed in future versions). It might not be present in future versions.

I still think there might be the possibility to "force" the UV1(or uv2) to be included but I haven't figured out how yet.

Here you can see the mesh in the prefab (inside the project)
image
And here the mesh included in the bundle
image

You can see the bundle mesh is missing a lot of information

@MichaelBezzina
Copy link
Author

Oh yeah, I remember that thread. I'll try to find a reported Unity bug regarding this or post one myself then.

If you do find out a way to force the inclusion of the UV1 or have any ideas that are worth trying out, please let me know. I'll start investigating that further and also post if I find anything promising.

Thanks for the clarification in those screenshots as well!

@Ayfel
Copy link
Owner

Ayfel commented Oct 26, 2022

You are welcome, and let us know if you get some clarification from Unity or find out a good solution : )

@MuhammedResulBilkil
Copy link

Oh yeah, I remember that thread. I'll try to find a reported Unity bug regarding this or post one myself then.

If you do find out a way to force the inclusion of the UV1 or have any ideas that are worth trying out, please let me know. I'll start investigating that further and also post if I find anything promising.

Thanks for the clarification in those screenshots as well!

Did you find any solution? I would like to use this Prefab Lightmapping with Addressables. I have not tried it yet but addressables works with asset bundles under the hood.

Unity Version: 2021.3.14f1 LTS
Addressable Version: 1.21.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants