- Home /
Replace GameObject vs. replacing mesh and material?
Hi! I am working on a game in which GameObjects are being replaced frequently, sometimes up to 10 in one second. The only thing that changes is the object's material and mesh. Would it be wiser performance wise to instead copy the material and mesh from the new target GameObject instead of destroying the old and instantiating the new, or would that require more/the same amount of memory?
Thanks
Answer by whydoidoit · Jun 21, 2013 at 09:24 AM
Avoid instantiating at runtime if you possibly can - it's pretty expensive in performance terms. If there is at least one active copy of the mesh somewhere in the scene then it won't need to be uploaded to the GPU - you might make a tiny scaled version of each mesh and material for instance, or have copies that are never going to be seen because they are kilometres away from the main game - that will give you the greatest performance.
Answer by GenoGenova · May 17, 2015 at 07:13 PM
Hello and thank you for your answer.
Would it be the same case if for instance you make a customisable character and want to change its armor, weapon etc... at anytime, would you import the mesh in the scene somewhere bellow the ground already. or would You just load the game object from your resource folder with Instanciate ?
armor = Resources.Load("ArmorGOLD") as GameObject;
Instantiate(Armor);
I am just scared that on the last case you might have 1 or 2 sec delay while you change armors each time.
regards
Please, ask you new question by opening a new post. Do not use answer section to ask a question.