- Home /
Enable or Instantiate
Hi, so my question is what will be better way to do this.
So I have object that will have other models over time (like going to next stage), without going back. Should I have them all parented to gameobject, and enable/disable, or instantiate and destroy each one seperately?
Answer by bram_v_e · Apr 10, 2017 at 07:14 PM
Enabling them sounds like the slightly better option. Enabling has a slight performance advantage over instantiate however it is nothing to write home about. Both ways will work just fine!
Answer by kchhibber · Apr 10, 2017 at 08:22 PM
It depends on how many objects(models) you are planning on having. Sometimes when you instantiate and destroy objects on demand in the game it can affect performance(For example: Frame rate).
This is where people use the Object Pooling concept which allows you to instantiate the maximum possible value of gameobjects while the game is loaded which is called the pool and then enable and disable them as required.
The advantage of this is that the pooled object is obtained in predictable time whereas creation of the new objects (especially over network) may take variable time.
You can watch this tutorial and see if this help you decide which approach to go for: https://unity3d.com/learn/tutorials/topics/scripting/object-pooling
Hope this helps!
Answer by mnarimani · Apr 10, 2017 at 06:29 PM
It depends on frequenty of it, Instantiating and destroying object will trigger Garbage Collector and the performance will go down, but if you keep the instantiating and destroying rate down, I guess you will have no problem. but if you see the frame rate goes down, you need to enable/disable gameobjects
Your answer
Follow this Question
Related Questions
[solved]how can i enable or disable a component of instantiated objects? 5 Answers
Select an enemy to attack with buttons? 2 Answers
Checking if object intersects? 1 Answer
Efficient grid system 1 Answer
Prefab using same particle System ? 0 Answers