- Home /
Best Way to Create Pile of Gold Coins
I currently have a single gold coin modeled, imported into Unity, and made it a prefab. Now I also want to make a pile of gold coins with the same coin so I can make something like a treasure room. What would be the best way to do this performance-wise?
In Blender, I duplicated that single coin many times and spread them out to make a gold pile. Then rendered an image from the top view to use as a texture. I then modeled a low poly mesh in the shape of a gold pile and put the texture on it. The problem is that it looks very flat when done this way.
I was wondering if it would impact performance if I made a gold pile from the coin in Unity by duplicating the prefab multiple times and then turning the finished gold pile into another prefab. Once a prefab is loaded, does it have to load it again for each instance of it?
I did some searches but most of the results were related to gold farming.
Answer by Chronos-L · Feb 16, 2013 at 07:10 AM
In Unity, there is a built-in script ( CombineChildren.cs + MeshCombineUtility.cs ) for combining mesh in the children object ( Assets -> Import Package -> Scripts ).
The following is the comment from the script:
/*
Attach this script as a parent to some game objects. The script will then combine the meshes at startup.
This is useful as a performance optimization since it is faster to render one big mesh than many small meshes. See the docs on graphics performance optimization for more info.
Different materials will cause multiple meshes to be created, thus it is useful to share as many textures/material as you can.
*/
So, by parenting all your coins to an empty object and attach CombineChildren.cs to the empty object. A new mesh containing all the coins' meshes will be generated at runtime; and according the comment "it is faster to render one big mesh".
P/S: If all the pile of gold coins are going to look the same anyway (or you are going to have just 3-5 different looking piles), you can just join them in Blender as one object before exporting it to Unity (so you would not need to combine them in runtime).
Thanks, but I think combining them into one mesh would make it too high poly. The coin pile texture I made in Blender is from spreading out a bunch of the same coin (80 Tris each). In the end, all coins combined is 25,200 Tris, which is way too many. If Unity only loads the same prefab once no matter how many times I use it, I think that would be a better solution, but I'm not sure if it does load only once.
I am not exactly sure how the Unity works with prefab. Perhaps this article will be able to help to figure out the answer to your question, and it might help you improve the performance of your game as well.
Thanks for the link. I learned a thing or two about performance, but it still didn't really answer my question. However, reading about draw calls, I guess I can just experiment and see if making the gold coin pile with multiples of the same prefab increases the draw calls.
After experimenting, the number of draw calls stay the same if I reuse the same prefab multiple times, but the Tris/Verts count goes up, obviously. I guess to get the best of both worlds, I can do what I did and create a low poly mesh to put the coin pile texture on, and then put a few 3D coins sticking out so it doesn't look so flat.
Your answer
Follow this Question
Related Questions
Not a question - just some performance metrics for rendering from Unity scripts 0 Answers
What Techniques are used for multi-level games and keeping APK size to minimum? 2 Answers
Are prefabs better for performance? 1 Answer
Does enabling/disabling Scripts have a high performance cost? 1 Answer
All project as child of one gameObject is a good idea? 1 Answer