You model probably uses UVs outside the range 0…1. Try turning on “consider UVs”. Does this fix your issue?
Re: Combining meshes and using the Batch Prefab Baker. I would suggest running the Batch Prefab Baker first. And then combining some of the meshes. This is because the meshes are very easy to work with once they all use the same material. You can combine them with just a regular Mesh Baker or using Unity’s Mesh.CombineMeshes.
It was a pain because before I wasn’t using a scene - I was just putting a mesh baker in each prefab that I was using. This workflow is definitely more complicated.
Anyway, I got the batch prefab baker working, and then of course I had to merge a some of the meshes, which was the whole point of doing this. Unfortunately, when I run a texture baker on the output of the merged batch, I get this error:
Value was either too large or too small for an Int32.
at System.Convert.ToInt32 (System.Double value) [0x0007a] in <321eb2db7c6d43ea8fc39b54eaca3452>:0
at DigitalOpus.MB.Core.MB3_UVTransformUtility.GetEncapsulatingRectShifted (DigitalOpus.MB.Core.DRect& uvRect1, DigitalOpus.MB.Core.DRect& willBeIn) [0x00013] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\MB3_UVTransform.cs:363
at DigitalOpus.MB.Core.MB3_TextureCombinerMerging.MergeOverlappingDistinctMaterialTexturesAndCalcMaterialSubrects (System.Collections.Generic.List`1[T] distinctMaterialTextures) [0x00339] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombinerMerging.cs:172
at DigitalOpus.MB.Core.MB3_TextureCombinerPipeline+<__Step1_CollectDistinctMatTexturesAndUsedObjects>d__9.MoveNext () [0x00a01] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombinerPipeline.cs:492
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00046] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:315
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00033] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:328
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00033] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:328
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00033] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:328
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00033] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:328
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00033] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:328
at DigitalOpus.MB.Core.MB3_TextureCombiner.RunCorutineWithoutPause (System.Collections.IEnumerator cor, System.Int32 recursionDepth) [0x00033] in C:\Code\TestProject\Assets\MeshBaker\scripts\core\TextureCombiner\MB3_TextureCombiner.cs:328
at MB3_TextureBaker.CreateAtlases (DigitalOpus.MB.Core.ProgressUpdateDelegate progressInfo, System.Boolean saveAtlasesAsAssets, DigitalOpus.MB.Core.MB2_EditorMethodsInterface editorMethods) [0x0000d] in C:\Code\TestProject\Assets\MeshBaker\scripts\MB3_TextureBaker.cs:568
UnityEngine.Debug:LogError (object)
MB3_TextureBaker:CreateAtlases (DigitalOpus.MB.Core.ProgressUpdateDelegate,bool,DigitalOpus.MB.Core.MB2_EditorMethodsInterface) (at Assets/MeshBaker/scripts/MB3_TextureBaker.cs:576)
DigitalOpus.MB.MBEditor.MB3_TextureBakerEditorInternal:DrawGUI (UnityEditor.SerializedObject,MB3_TextureBaker,UnityEngine.Object[],System.Type) (at Assets/MeshBaker/Editor/MB3_TextureBakerEditorInternal.cs:441)
DigitalOpus.MB.MBEditor.MB3_TextureBakerEditor:OnInspectorGUI () (at Assets/MeshBaker/Editor/MB3_TextureBakerEditor.cs:37)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Ok thank you. Got it working now.
Hello I am having a problem.
I have tried many different setting but every time I try to bake this mesh it comes out with blackish sides.
I have tried with and without making a texture atlas. The same result even when using the source
material.
Any ideas of things to try?
Here are pictures before(Source) and after (baked).
This looks like a problem with the normals or tangents. What shader are you using? Is there a normal/bump map? What does the baked normal/bump map look like? Is it the usual purple color or more of a redish color? Is the texture marked as a “normal map”?
After you have batch prefab baked, you should be able to combine these meshes just using a Mesh Baker without a Texture Baker. The Texture Baker should not be needed because the meshes all use the same material.
The error from the texture baker is a bit troubling? Is there a huge amount of tiling (more than 1000 times) on these meshes?
Thanks that fix the UV but the quality is pretty low now because the textures seems to be repeting.
It works for smaller objects though.
How do I save the mesh filter? the field is empty after I click on “Bake all child meshbaker”
@Invector
Yes, the consider UVs will bake the tiling into the atlas. If there is a lot of tiling, it is good to use the multiple materials feature to put those textures on their own submesh. See this video for details:
Re: Mesh Filter empty after click on “Bake all child meshbaker”. Is this happening to your combined mesh object? Is it a prefab that is used in multiple scenes? If so then the problem is that the mesh needs to be saved as an asset in the project folder. Use the “output = bake into prefab” option to make this happen. The “output = bake into scene object” will save the mesh as part of the scene. It will only exist in this scene.
If the mesh is disappearing within the scene then there is probably an error. Check the console for errors.
Does this answer your question?
How I can combine skinned mesh at runtime?
There are several example scenes in the project with simple scripts that combine skinned meshes at runtime. Can you provide more information about what you want to do?
If possible try to bake the atlases in the editor. This process creates a big lag.
SceneRuntimeExample_SkinnedMesh: This bakes four MeshRenderer cubes into a single skinned mesh.
SkinnedMeshRenderer: This scene combines several animated skinned mesh characters and some MeshRenderer props into a single skinned mesh.
CustomizeCharacter: This scene combines different combinations of skinned mesh body parts on an animated customizable character.
This video has a lot of information about how to bake skinned meshes.
This video explains how to create customizable skinned mesh characters.
Does this answer your question?
I have a character that can change up to 100 outfits at runtime. I need to combine after the user chooses the outfit. How I can do this?
For character customization, study these two scenes, and watch this video:
- CharacterCustomization.unity
- CharacterCustomizationSetup.unity
Hello Everyone, I wanted to check if anyone had this problem before, I’m a bit lost
When baking lights, after replacing all my mesh prefabs with Batch Prefab Baker, some of my meshes are partially or all black:
-
The baked prefab is broken, so every barrel is broken, every purple carpet, etc. Every other mesh is okay (only the light bake is broken, the prefab’s color textures are fine)
-
Original Prefab bakes fine (has a custom lightmap)
-
Batch Baker prefab is on “Copy uv02 unchanged” I checked and the lightmaps seems to be the same as the original, they are not broken or missing. I even exported the new barrel to Maya to checks uvs and it’s OK.
-
I’m using Bakery to bake lightmaps.
-
Same problems replicate in a smaller scene.
-
Checking on the original meshes import settings, but I don’t notice anything weird, or different from other meshes
Edit:
- Recently tested the “Generate_new_UV02_layout” on Batch Prefab Baker, and the problems persists, so it seems it doesn’t have anything to do with lightmaps
- FIXED: It had to do with import tangents of these meshes, changed the broken meshes from “none”, or “import”, to “calculate mikktspace”
Sorry for the slow reply, glad that you found a solution. Interesting that the tangents worked with the original meshes but not with the baked ones. I will think on that.
No problem, and thanks for the reply.
I got another question, Is there a way to “re bake” prefabs , every time I want to do it, I have to deleted the older ones and start again, the Batch Prefab Baker doesn’t replace the existing ones. Deleting the older ones also breaks the references in other scenes or prefabs, so each time I would like to add or remove a prefab, or material to the atlas, I would have fix every missing reference. Just trying to find the best workflow.
Yes, you can re-batch-bake the prefabs. This is easiest if you saved your original batch prefab baking scene.:
- Make the changes you want to the source prefabs and apply the changes to the source prefabs.
- Bake the textures on the source prefabs into combined material(s).
- Hopefully you saved the original batch-prefab-bake setup scene. Otherwise you need to set up your batch prefab baker again with the prefab rows. Your source prefabs go in the ‘source prefab’ slot. The prefabs you are using in your scene go in the ‘Result Prefab’ slot.
- Re-Batch-Bake the prefabs. This will update the prefabs in all scenes in the project where the prefabs appear.
Mesh Baker also includes a tool “Window → Mesh Baker → Replace Prefabs In Scene” that you can use to replace the prefab instances in a scene with batch baked versions. It is smart enough to keep changes you might have made to the instances like scale, position, rotation and other properties.
Yep, I’m doing that, I guess my problem is that the “replace prefabs in scene” windows usually is empty. Is good after baking, but after changing scene or closing unity gets like this.
Tried saving the settings, and the batch prefab baker as a prefab, but always there is something that makes me delete and rebake all prefabs again.
Will keep trying, maybe I’m doing something wrong or forgetting something, I think I had it working once, but this scene just has to much stuff going on.
I like to bake in a different scene than the main game scene, so I use this workflow:
- In game scene, I add a TextureBaker + BatchPrefabBaker
- Use tools for collecting instances of objects I want to bake in the TextureBaker
- On the Batch Prefab Baker press button “Populate Prefab Rows From Texture Baker”
- Now make a Prefab from the TextureBaker + BatchPrefabBaker GameObject
- Close the scene and create a new Baking scene
- Drag the TextureBakerAndBatchPrefabBaker prefab into the new scene. The Batch Prefab Baker should have all the prefabs in it.
- On the Batch Prefab Baker “Create Empty Result Prefabs”
- Create source instances in the scene using BatchPrefabBaker context menu command “Create Instances For Prefab Rows”
- Drag the source prefab instances to the Texture Baker lost of objects to combine.
Now the setup scene is ready for baking.
Hello,
I have just started playing around with MeshBaker and watching the tutorials. I’m not sure how to go about my use case though.
I have bought a building kit asset which has a lot of prefabs consisting of multiple child prefab “building blocks” to create bigger buildings. I am trying to figure out if it is useful for me to combine textures for these because many of the building blocks appear in all of the prefabs and ofc, use the same material. If I use texture baker and mesh baker to combine the materials and meshes, I am ultimate going to end up with a combined material for every prefab at that point, which means a huge number of textures, right?
What I am trying to wrap my head around is if it’s possible to somehow combine some materials and reuse them across all of my prefabs that were using the same original material. Kind of feels like trying to have my cake and eat it too