Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
12
Question by alexnode · Apr 20, 2010 at 12:07 PM · prefabhierarchycloneduplicatecopy

Placing Prefabs in Prefabs.

I have a scene Hierarchy which looks like that

  • root prefab (from an empty game object)
    • architecture prefab
    • plant prefab
    • plant prefab
    • plant prefab

When I drag a new root prefab in the scene everything works fine. If I change my first plant prefab all the plant prefabs change. But I found this thread in the forum that suggests otherwise. here

Am I missing something ? I use similar hierarchies for pretty much everything in my scene so if I do something wrong It would be NO good.

///Edit/// I see what is the problem now. If I change my original mesh things will update because everything points back to the original mesh. But if I do things in unity the prefab connection is lost. hmmm i still need to create groups of geometry with prefabs for cloning in an efficient way ... I really don't want to write code for placing 30 plants, garbage bins etc in the right place.

Comment
Add comment · Show 5
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 alexnode · Apr 20, 2010 at 01:46 PM 0
Share

A really crude workaround I found so far is to put my architecture prefab in 0.0.0 create an empty game object at 0.0.0 (Not prefab) with my props as children. Then when I add a new instance of my architecture model, I duplicate the game object with the props and move it to the new coordinates.No root prefab !!! Looooads of work ...

avatar image spinaljack · Apr 20, 2010 at 02:24 PM 1
Share

What's the question?

avatar image alexnode · Apr 20, 2010 at 03:12 PM 0
Share

lol, sorry I got lost a bit. Can I use prefabs in prefabs if no what is the best way to clone ready made areas of my scene?

avatar image Novodantis 1 · Apr 22, 2010 at 10:38 AM 0
Share

I am also interested in whether prefabs-in-prefabs is possible. I have ships made of pre-set components, which themselves I'd like as pre-set classes. So +1 for a good answer to this! =)

avatar image Rennat · Dec 03, 2010 at 07:48 PM 0
Share
  • nested prefabs would be nice

9 Replies

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

Answer by Tetrad · May 04, 2010 at 09:53 PM

You can't have the concept of "nested" prefabs, no.

What you could do is set up some kind of dummy gameobject/node that, on Awake(), Instantiates your desired prefab at it's current position/rotation/scale.

So each game object that's a child of your root prefab would have a script that looks something like this:

class PrefabSpawner : MonoBehaviour { public GameObject prefab;

 void Awake()
 {
         GameObject go = Instantiate( prefab, transform.position, transform.rotation );
         go.transform.parent = transform.parent;
         Destroy( gameObject );
 }

}

Comment
Add comment · Show 2 · 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 Woutor · Jun 02, 2010 at 02:43 PM 0
Share

The problem here is that this does not make the prefab visible in the editor, is there anything to remedy this?

avatar image DaveA · Aug 06, 2010 at 01:02 AM 0
Share

Perhaps an Editor script could do that (make them visible that is). There is a 'material generator', maybe it would work something like that?

avatar image
3

Answer by Bento-Studio · Mar 12, 2012 at 01:36 PM

Maybe our last plugin may help you! http://u3d.as/content/bento-studio/nested-prefab/2Jz

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 Antony-Blackett · Apr 05, 2011 at 11:52 PM

I know exactly what you want to do and I too cannot find a way to do it. :/

If I'm not mistaken you want the ability to create 'prefab links' in much the same way you get asset links. This would then allow you to have a number of objects and be able to use them individually as well as have a 'prefab links' hierarchy for common layouts etc.

You would think this would be an easy feature to add. it seems half the functionality is there with the asset linking.

Here's an example for people to help understand the problem.

I want to be able to do this (imagine this is the project view):

  • prefab1
  • prefab2
  • commonLayoutPrefab
    • prefab1
    • prefab2

Changing prefab1 or prefab2 under commonLayoutPrefab should be the same as changing prefab1 or prefab2 at the base level as the ones under commonLayoutPrefab are only links to the originals.

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 jlreymendez · Apr 05, 2017 at 09:41 PM 0
Share

I found this question looking for exactly what you mention. Boy would that be a nice feature to have.

avatar image
0

Answer by spinaljack · Apr 20, 2010 at 07:55 PM

If you want to copy and paste sections on the scene use ctrl click on each item in the hierarchy window and then simply drag the whole lot into an empty prefab, then you can drag that prefab onto the scene as many times as you want.... I'm not sure it that's what you wanted though.

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 alexnode · Apr 21, 2010 at 08:25 AM 1
Share

Thanks for your reply, but no it is not what I want. This is what I was doing but in this way you loose the connection of the prefabs inside the root prefab. Let's say you have 30 plants (prefab) inside a building (prefab) if you turn the plants and the building in a root prefab then the plants become unique. The solution I am working today is to delete the plants on runtime and replace them with a plant prefab that takes their coordinates and values. But I have some problems with it.

avatar image
0

Answer by jakerman999 · Jan 13, 2011 at 06:56 PM

If you're looking for what I think you're looking for you can do it with the transform.parent property. I'll share a function I'm using to Instantiate hex cells in this manner.

function Cellspawn (colour, Colour) {
    cell = Instantiate(colour, pos, Quaternion.identity); //create the cell
    cell.GetComponent(tilemove).row = row; //set the row variable
    cell.GetComponent(tilemove).column = column; //set the column variable
    cell.transform.parent = this.transform.Find(Colour).transform;  //set the cells parent
    if (special ()) {
        cell.GetComponent(tilemove).special=true; //sets special flag
    }
} 

In a running instance the hierarchy tab shows the cells nested within there own colour tags, which are empty gameobjects nested within the gameobject that spawns the cells. This I have set up beforehand although the colour tags could be created at runtime. The special function is really just a huge mess of if statements and spaghetti code I didn't want to look at anymore.

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
  • 1
  • 2
  • ›

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

6 People are following this question.

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

Related Questions

How should I structure this in Unity? 1 Answer

How do I properly duplicate an object in a editor script? 3 Answers

How can I duplicate an object and place it randomly near the original ? 0 Answers

Duplicate prefab and all its variants to new prefab with new variants 0 Answers

Possible Unity Glitch. A few lines of code erasing prefab data. 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