- Home /
Put all GameObjects of a scene into a prefab
I wonder if it's okay to put all GameObjects of a scene into a single prefab, so I could Instantiate it instead of LoadLevel.
If it's okay, what's the difference between those two methods? Is there any additional overhead?
What exactly is the prefab? Thanks!
Answer by Muuskii · Jul 27, 2012 at 12:13 AM
Seems like the difference would be that after you've loaded the prefab all the objects that were previously there would still be around. You could delete them, and have the overhead of deleting objects one at a time. But why would you want to do this?
Ok,let me explain: I made a game which had 10 levels. Now, I want to slice the game window into 2 parts vertically, and each part is independent to the other one. By doing this, I can not use LoadLevel, since it would affect both parts.
Oh! That makes sense. In that case you might be able to use DontDestroyOnLoad but I don't see a way of "YesDestroyOnLoad" When you're finally done with it. So if you have a "root empty" parenting all the elements to a prefab based level you should be able to easily destroy it and all it's childern. I thought there was a function for this but I can't find it at the moment.
I can see why this might have some performance issues, so it might be a good idea to split levels into smaller prefabs where line of sight is blocked from one segment to the next. Loading segments as you need them. . .
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Unity fire1 prefab in code 2 Answers
Changing value of prefab without effecting all instances. 1 Answer