Advantages of instantiating prefab vs gameObject?
Pretty simple question, what are the advantages if any of instantiating a prefab vs an existing inactive gameObject?
I personally find using gameObjects to be easier, I can tweak them to my liking while they're in place such as child UI element, and just set them to inactive until I'm ready to use them. When I instantiate all I have to do to the clone is match its hierarchy parent to the original and set it as active.
Prefabs on the other hand, if there are any modifications that require the prefab to be in it's place, I have to manually place it where it will be in the hierarchy to make changes, apply my changes and delete it from the hierarchy. Additionally placing it properly back into the scene hierarchy on instantiation is a chore.
Well actually just activating is pretty good because it won't lag your game on activating as much as instantiating a new gameobject. But it has also some bad sides. If you have to many GameObjects (even if inactive) the game will use more RA$$anonymous$$. so if you want to use less RA$$anonymous$$ you should instantiate. If you want to have performance you should just reactivate the GameObjects.
I guess the advantage of a prefab is that they all reference the same source components and only store the locally changed values in the instances.
That way if you use a pretty complex GameObject with lots of components, properties or containing a hierarchy of other GameObjects, you can just change the components, properties or hierarchy in the prefab and all instances in all your scenes (as long not locally overridden) will update to it.
I am mostly using prefabs if I have the slightest feeling that I will reuse it somewhere. In rare cases, I am also using local "offscreen" GameObjects, that I assign as pseudo prefabs to my scripts to instantiate.
I have to agree that editing is sometimes a pain. You can edit the properties of all first level children of the prefab, but have to temporarily add it to the scene to do changes to deeper children or the hierarchy. Still I learned to live with this and think prefabs are a very useful thing. :)
Answer by ArturoSR · Sep 01, 2016 at 07:14 PM
Hi, OK, the advantage between an original and an instance is as follows:
The game object (prefab) could be part of a pooling system, this allow less process for the application when you only "moves" the dead object to another location and set it alive again.
The instance is a "copy" from a prefab, you can generate many copies as you need them but can have a cost about processing frames, normally you use this case with particle FXs (appears, do his job and die) and must not leave any trace about it (memory space).
So, this is the more simply explanation about advantages from an original of a prefab and an instance from a prefab, but essentially both are "instance" from a prefab, only the use of each one changes, cheers.
Your answer
Follow this Question
Related Questions
How can i define a costume function for an object in a prefub that I spawn? 1 Answer
Problem Instantiating a Prefab 1 Answer
GameObject created from Prefab, much larger than original object 0 Answers
GameObject spawning at several Y distance below my spawn point 0 Answers
Switching out GameObject with Prefab? 2 Answers