Sending cubes to prefab makes their mesh settings vanish

Say i place 30 cubes procedurally and combine them into a parent object via script.

Is it possible to take the cubes parent object and to make a prefab with it? Because every time i do, all the cube mesh filter and renderer settings vanish, and prefab contains only invisible cubes with no mesh settings.

I attempted via dragging from hierarchy to prefab, code: ReplacePrefab, and copying from hierarchy during play pasting back in edit mode… the prefab cubes meshes are gone.

why does it happen? do you have a suggestion?

Edit - Maybe because i procedually changed all the cube’s UV offsets? it shouldnt stop from prefabbing them?!

i have tried both with CombineChildren and without, same result, i would also like get the Combined Children mesh and save it as a prefab.

EDIT- i just found that if i combine mesh and delete the children, the combined mesh still exists in parent object (The children were redundant and undeleted?!) but it becomes invisible if i try to drag the comined mesh parent object into a prefab.

alt text

It’s not enough to create a prefab of a combined Mesh. The combined Mesh is a temporal mesh which is created in memory. You have to save the Mesh as asset if you want to use it as asset.

That means you have to use AssetDatabase.CreateAsset to store the new Mesh in your project. Keep in mind that those are classes from the UnityEditor namepsace, so use them in an editor script only or you can’t build your game.

why does it happen?

When you batch meshes, Unity makes an entirely new single mesh for each material. It then disables (but does not delete) the original mesh renderers, leaving behind only the new Combined Mesh. You can try making a prefab of the combined mesh, but that mesh won’t have any colliders (batching doesn’t combine those).