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 /
avatar image
1
Question by JoshOClock · Dec 29, 2011 at 04:40 AM · prefabs

Can I make Prefabs that contain other Prefabs?

I'm trying to create a prefab of prefabs without losing all the connections.

Let me elaborate: I have a barrel that is a mesh and some scripts assigned. So I create a prefab of it so I can place it throughout my levels easily.

I decide sometimes I want a group of stacked barrels sometimes instead of just one. So I create an empty game object that has 4 children that are my original barrel so I can easily place stacks of barrels throughout my levels.

However once I make a prefab of this empty game object I lose all the connection between the original barrel and the child barrel. This isn't ideal as I'd still like the barrel children to be 'barrels' so if I add a script or change a value in the original I'd like any barrel anywhere to take this data... however since I've lost the link between the orignal this doesn't happen.

Is there a better way to do this?

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 · Dec 29, 2011 at 09:10 AM 0
Share

No. Unity doesn't support nested prefabs as of yet, although it's on the roadmap. When it will be available is subject to great mystery.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by save · Dec 29, 2011 at 07:44 AM

Nested prefabs is on the wishlist, go vote. ;)

What you could do to maintain your working structure is to have placeholders in the level, then in Awake() or Start() instantiate them.

 function Awake () {
     var placeholders : GameObject[] = GameObject.FindGameObjectsWithTag("BarrelSpawn")
     for (var placeholder in placeholders) {
            Instantiate (barrelPrefab, placeholder.transform.position, placeholder.transform.rotation);
     }
 }

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
1

Answer by Bento-Studio · Mar 12, 2012 at 02:07 PM

I you are still interested by nested prefabs in prefabs, I have created an editor extension : http://u3d.as/content/bento-studio/nested-prefab/2Jz

This extension allows you to make prefabs that contains other prefabs and so on.

Comment
Add comment · Show 1 · 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 Tseng · Mar 12, 2012 at 06:34 PM 0
Share

There is no need for such a solution. Unity3D 3.5 made the first step to include nested prefabs (you can add or remove components from prefab dragged into the scene without breaking the prefab), which is a first step for a built-in nested prefab solution

avatar image
0

Answer by JoshOClock · Dec 30, 2011 at 04:41 AM

Since I already had a copy of all my prefabs as well as having created a number of objects that contained versions of these prefabs, here is the code I ended up using:

 public class NestedPrefabScript : MonoBehaviour {
 
 public Transform[] m_NestedPrefabList;

 // Use this for initialization
 void Start () {
     foreach (Transform child in transform)
     {
         foreach (Transform nestedPrefab in m_NestedPrefabList)
         {                
             Debug.Log(child.name + " " + nestedPrefab.name);
             if (child.name == nestedPrefab.name)
             {
                 Vector3 childPos =  child.position;
                 Quaternion childRot = child.rotation;
                 
                 if (child.collider)
                     child.collider.enabled = false;
                 Destroy(child.gameObject);
                 
                 Debug.Log("Replaced!");
                 Instantiate(nestedPrefab, childPos, childRot);
             }
         }
     }
     
     transform.DetachChildren();
     Destroy(gameObject);
 }

Caveats are that my parent object that contains all the nested objects was empty other than being a container for all my nested objects.

Worked for me. Hopefully someone else finds it remotely useful.

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

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

Related Questions

Count Prefabs on builded .apk 0 Answers

Multiplayer different player prefab 0 Answers

PrefabUtility does not exist? 1 Answer

how can i make prefabs keep there inspector varibles 1 Answer

(Re-posted) How to save multiple of the same prefab clones 0 Answers


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