- Home /
Creating one gameobject from several prefab meshes
I have a tile system setup that is generated at runtime. I then instantiate a hexagonal prefab underneath each node of the tile to create the terrain. However, doing it this way results in a gameobject for each tile I create. How can I put one gameObject together that is the combination of the hex prefabs?
Answer by Cherno · Sep 07, 2014 at 02:01 AM
It's procedural generation, and there are several ways of achieving what you want. The most basic one is how most Minecraft-clones/Voxel-based games do it: Generate the complete mesh by script, setting the position of each vertex, the triangles, and the UVs by hand.
Another way is to take the mesh from an existing gameobject (like a prefab, or just a mesh in your Resources folder) and copy the vertex, triangle, uv etc. data for your own script-generated mesh. You could also just use the MeshCombine function although I'm not sure how uv mapping is handled there.
Take a look at this thread, specifically the latest short discussion between me and another user:
The prefab gameobjects themselves can't be combined as a whole, but as outlined above you can take their vertex, texture etc. data and combine these pieces of information into a new object.
I made a hex generating script a while ago myself for a BattleTech-style game, you ca see some screenshot in this thread, feel free to ask if you would like to know any specifics or have a look at my project file.
Your answer

Follow this Question
Related Questions
Repeating Images From an Atlas 0 Answers
How to get at the 'status' of a game object? 1 Answer
multiple meshes in a prefab and how to texture? 1 Answer
Generate the world 0 Answers
Replacing skinned mesh prefab problem 0 Answers