- Home /
Design Best Practice Question
Hi, In my 2D game, the player can have one of many different robot followers. Each Robot will have a variety of diferent abilities and exist as separate gameOjects currently. Right now, I have about 10 different potential followers.
Question: If I want my player to be able to choose one of these robots to follow them, do I need to include ALL 10 game objects in the scene, and activate only the one that was selected? Or can I dynamically add only one to the scene after the player selects it.
Question Part 2: Are there performance issues related to have many elaborate inactive gameobjects attached to a scene? Is it ok to add any number of gameojects, so long as they are not active, performance will not be impeded.
Thanks!
Please note that open ended design questions like this are better suited for the forums.
Try to limit questions on UA to a single specific technical question.
Answer by Fmressel · Oct 15, 2014 at 01:33 AM
If all the robots are active during the choosing stage and they all have scripts that do lots of updates every frame, then yes I think that would have an impact on your performance.
As for performance issues while they are inactive, I found this article:
http://answers.unity3d.com/questions/462942/does-inactive-objects-eat-up-performance.html
And for how I would deal with this issue:
I would have a script that just turns off all the scripts that are not needed on the robots during the choosing stage.
Then once the choosing stage is over; destroy all the robots that the player has not chosen and activate the needed scripts on the chosen robot.
If you need to go through the choosing stage more than once without reloading the level (ie: the choosing stage is in the same level file as the gameplay stage) and you are worried about performance, I would not just destroy the robots but use object pooling instead.
Hope that helps! Let me know if I did not answer your question correctly or you need more explanation!
That's very helpful Thanks! I will try this for sure. Thanks again
Your answer
Follow this Question
Related Questions
Very weird dark level loading? 4 Answers
Design approach opinion needed on tilemap vs gameobject 0 Answers
Best practice : Image.enable vs go.SetAactive() 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How to structure code for squad selection and movement 0 Answers