- Home /
What is the Performance implications of stacking gameobjects and switch between them for character customization.
Are there any performance draw backs to simply stack weapons on the Hand socket and disable all of them except the one used and when switching to a different weapon u just enable that other object that will already be in place.
I am mainly concerned about mobile since it will be about 120 gameobjects on one character that i will be using to customize the character.
Is this a bad idea and is there a better way? or should i just instantiate the needed objects when switching weapons and rotate them in the correct way?
Answer by unity_ek98vnTRplGj8Q · Jan 02, 2020 at 09:28 PM
There is a performance drawback associated with calculating the new transforms for each weapon, so when you move the hand it will have to move 120 gameobjects with it. Doing this will also force you to load all weapons on start up, which will make loading times longer
On the other hand, there is a performance benefit to simply enabling and disabling gameObjects rather than instantiating them. This is similar to object pooling, which is used commonly to fire projectiles rapidly so you don't have to re-instantiate and destroy a projectile every time. This will only make a difference for you if a) you plan on swapping weapons very frequently and rapidly or b) the weapons are very complicated and take a long time to instantiate and initialize.
If you do want to use this method, I recommend at the very least moving the deactivated gameObjects to a static container so their transforms aren't being updated constantly while they are deactivated.
Your answer
Follow this Question
Related Questions
What is wrong with my code? (Unity 2018, C#) 2 Answers
connect a cube and a circle in unity editor ( not by code please) 0 Answers
windows powershell has stopped working 1 Answer
Is there a way to use dynamic variables with scriptable objects in the editor? 1 Answer
Security Update - If I install latest udpate of Unity, do I need to intall the security patch too? 3 Answers