Jump to content
Sign in to follow this  
Xkynar

Unity 5 Pseudo-Prefabbed Lightmap UV problem

Recommended Posts

I am using Probuilder Basic for a few prototyping on a procedurally generated map. As such, I need to instantiate the map on Runtime, which consists of creating several Prefab Rooms.

 

Since Unity 5 doesn't support Lightmapped Prefabs, Unity's employees provided a sample project with a solution in this thread: http://forum.unity3d.com/threads/problems-with-instantiating-baked-prefabs.324514/

 

The solution basically consists of baking every prefab in a separate scene, saving the lightmap data in a special script which, on Awake, adds the lightmap information to the instantiated prefab in whatever scene it is instantiated in.

 

This method worked well in Unity's basic shapes. However, in Probuilder's objects, this happens:

 

ngqATG5.png

 

The lightmap shows unmapped in each face's corner.

After some experimentation, I noticed that, while playing, double flipping the object's normals, or calling "conform normals" fixed the object, becoming this:

 

q9e4N4S.png

 

And after some more experimentation, I concluded that the method which fixes the UVs is "ProBuilder2.EditorCommon.pb_Editor_Mesh_Utility.Optimize()".

This Optimize method somehow fixes the UVs, but since it is an editor method, I can't even call it in the object's start to fix the UVs.

Also, since I can't see what's inside, I can't know what is fixing the UV's.

 

Can someone help me find a solution to this problem?

Thank you very much.

Xkynar

Share this post


Link to post
Share on other sites

Optimize is what (among other things) generates the UV2 channels for a mesh.  A ProBuilder prefab doesn't store a Unity mesh, just the components needed to recreate it at runtime.  In the editor, if you drag a ProBuilder prefab into the scene ProBuilder can automatically generate the UV2, but at runtime the function is not available.

 

As a workaround, use the "Actions/Make Asset" to save the prefab mesh with the finalized UV2, then use that prefab instead.

Share this post


Link to post
Share on other sites

Ah, yes it's an advanced only feature.

 

You didn't hear it from me, but it would be pretty easy to recreate this feature with basic.  The Unity API you're looking for is "AssetDatabase.CreateAsset."

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×