Which is better: multiple meshes in the same prefab or different prefabs for each combination?
I want to create a prefab for my game characters so I can instantiate them programmatically. However, my game characters can be one of two genders, one of three races, and have seven variant models for each race/gender combination.
This means, combined, there are 42 different models that could be used.
According to http://answers.unity3d.com/questions/556851/change-prefab-3d-model-at-runtime.html the answer suggests I put every variant into the prefab and then just disable everything but the one used.
So which is more performant? 42 prefabs that only have the required meshes, or one prefab with 42 meshes, 41 of which are disabled?
Answer by Suduckgames · Mar 07, 2017 at 09:58 AM
What I do in this case, is to have a prebaf without mesh , and then add in the code the mesh as a childen in that way, So I can have a enemy prefab, and 20 differents models , If I want to add more modesl I just need add them to zombieModelArray and If i change something in the enemy prefab it affect them all
GameObject enemy = Instantiate(enemyPrefab, posicionInicial, Quaternion.identity) as GameObject;
GameObject zombieModel = Instantiate(zombieModelsArray[Random.Range(0,zombieModelsArray.Length)], posicionInicial, Quaternion.identity) as GameObject;
zombieModel.transform.localScale = Vector3.one * 0.42f;
zombieModel.transform.parent = enemy.transform;
I'm using my object as the player character during character select/creation... allowing them to customize the look of their character.
I suppose what I could do is create a single object with all the meshes... turning them on and off as they scroll through the options... and then destroy that object, instantiating the final option from the array when I create the actual in-game object in the next scene.
That's... actually quite brilliant. +1 for you!
Your answer
![](https://koobas.hobune.stream/wayback/20220612112237im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Idle Clicker Incremental Cost 1 Answer
'Reimport' not working 3 Answers
Getting trouble in migrating the Unity IAP old version to new version of IAP in existing project 0 Answers
Problem with Application.LoadLevel 0 Answers
adjust image size with mouse 0 Answers