Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 13, 2017 at 04:47 PM by FortisVenaliter for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by iMugen · Mar 05, 2012 at 08:20 AM · instantiateprefabdependenciesdisconnect

Prefab of a whole scene?

Hello all,

I looked around but couldn't find a definitive answer for this one. I recently found that I could instantiate whole scenes (objects), removing the need for me to make different scenes for my game (for this area at least). This also allowed me to make scripts that would change values specific to the level depending on which was being loaded. I would add the script and it would instantiate the proper prefab (prefab of prefabs). To my dismay I find that there is a disconnect between the prefabs within the "scene" prefab and the individual prefabs it's made of. I really liked this technique, is there no way to keep the connection to each individual prefab?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image asafsitner · Mar 05, 2012 at 11:15 AM 1
Share

Unity does not currently support nested prefabs. Watch out for future releases.

3 Replies

  • Sort: 
avatar image
9
Best Answer

Answer by Bunny83 · Mar 05, 2012 at 11:45 AM

Like @asafsitner mentioned Unity doesn't support prefabs in prefabs at the moment. But you can use scenes as second level prefabs ;). Just create your levels as scenes, make sure your scene has a master-GameObject ( preferable at [0,0,0] ) and parent everything to this GameGbject so your scene just contains one GameObject.

Don't turn this gameobject into a prefab or, like you've mentioned, you will loose all prefab connections in the scene. Just rename the master gameobject either to your level name or some general unique name.

To load a level, use Application.LoadLevelAdditive() or if you have Unity pro maybe Application.LoadLevelAdditiveAsync(). This will add the scene content to your current scene. Since every scene is a single gameobject you can easily delete one.

If you used the level name for he gameobject, just load a new level like this:

 // C#
 public GameObject MyLoadLevel(string aLevelName)
 {
     Application.LoadLevelAdditive(aLevelName);
     return GameObject.Find(aLevelName);
 }
 
 GameObject levelInstance = MyLoadLevel("Level1");
 //Now you can use levelInstance like a instantiated prefab.
 // Don't forget to destroy the old level by destroying the master-GameObject of the old level if you don't need the old level anymore.

If you want to use a general unique name like "LevelMasterObject", you should rename it after "Instantiate":

 // C#
 public GameObject MyLoadLevel(string aLevelName)
 {
     Application.LoadLevelAdditive(aLevelName);
     GameObject instance = GameObject.Find("LevelMasterObject");
     instance.name = aLevelName;
     return instance;
 }

Just make sure the level-scenes don't contain any other objects except the master gameobject.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iMugen · Mar 05, 2012 at 08:29 PM 1
Share

I tried this out and it works well. It's a much better method and I can just attach the script to the $$anonymous$$aster object. Thank you.

avatar image JayceeSalinas · Mar 16, 2014 at 02:51 AM 0
Share

I'm also trying to do something similar to this however when I add all my scene objects to the main empty $$anonymous$$aster Controller object objects that were children of other objects all become one child of the $$anonymous$$aster object. Am I not doing something correctly?

avatar image boringuser · Jul 20, 2016 at 07:49 PM 2
Share

This is very useful, thanks so much!

Note that LoadLevelAdditive has been deprecated. The new way to do this is Scene$$anonymous$$anager.LoadScene ("sceneName", LoadScene$$anonymous$$ode.Additive)

You can remove the scene with Scene$$anonymous$$anager.UnloadScene ("sceneName")

avatar image
1

Answer by clevermango · Jan 13, 2015 at 03:03 PM

I was needing to pull in an Asset Bundle of a whole scene, on a per scene basis from a Server.

I just -

1 - Create Prefab in Project Window

2 - Place an Empty Game Object inside

3 - Place the Prefab into the Scene

4 - Drag all Assets you want in the Bundle into the Prefab

5 - Drag the newly populated Prefab into the Project Window

6 - Run Asset bundle scrip with Dependencies (found here - http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundle.html)

7 - Select required save location

8 - Ready to use Asset Bundle of whole scene

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by astracat111 · Apr 13, 2017 at 04:40 PM

The easiest way, although it probably isn't recommended by some here, is just to go into the folder by right clicking "show in explorer", and in the explorer simply have a duplicated scene.

The only problem with prefabs is that you need to update them because you're making a copy, but then again even if you are working with prefabs, to be honest you need to have a really good base template system set before you expand and make a bigger game, so for me personally I just said 'screw it' and started copying scenes once my base template was done.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

setting the text of an instantiated prefab's child's guitext object 1 Answer

Get unity to recognize prefab in C# 2 Answers

Instantiated object rotation abruptly. 0 Answers

Instantiate prefab (button, texture) with attached script 1 Answer

instantiate problem with assigned variable 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges