- Home /
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.
i failed to prefab procedurally adited meshes, but i have found a script to export them as .obj files called EditorObjExporter it doesnt work yet but it's part of the same quest.
BTW, it would be great to have more information about how you "combine your mesh" and where you actually do this, at runtime or in an editor script.
just adding primitives into geometry shapes, combine mesh is done with combinechildren-extended-version from the forums with a frame delay of 2, and in the end it's easier to not make prefabs of the mesh just save the algorythm, although i did manage to make these into single meshes and export them as .obj's complete with color i may make an assetstore thing to make geometry sprites for games if people want, it looks retro! :)
Answer by Bunny83 · Sep 15, 2012 at 10:55 AM
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.
;) The editor offers twice the features you can use at runtime. Some things are a bit tricky but once you figured it out it's awesome ;)
you can combine the mesh and make a collider for it using combine mesh extended version for the forums. essential code!
Answer by DesiQ · Sep 15, 2012 at 10:27 AM
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).
Your answer
![](https://koobas.hobune.stream/wayback/20220613081039im_/https://answers.unity.com/themes/thub/images/avi.jpg)