x


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.

more ▼

asked Apr 20 '10 at 12:07 PM

alexnode gravatar image

alexnode
984 27 32 49

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 http://coordinates.No root prefab !!! Looooads of work ...

Apr 20 '10 at 01:46 PM alexnode

What's the question?

Apr 20 '10 at 02:24 PM spinaljack

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?

Apr 20 '10 at 03:12 PM alexnode

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! =)

Apr 22 '10 at 10:38 AM Novodantis 1

+1 nested prefabs would be nice

Dec 03 '10 at 07:48 PM Rennat
(comments are locked)
10|3000 characters needed characters left

7 answers: sort voted first

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 );
    }
} 
more ▼

answered May 04 '10 at 09:53 PM

Tetrad gravatar image

Tetrad
7.2k 27 37 89

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

Jun 02 '10 at 02:43 PM Woutor

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

Aug 06 '10 at 01:02 AM DaveA
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Mar 12 '12 at 01:36 PM

Bento-Studio gravatar image

Bento-Studio
61 1 3

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 05 '11 at 11:52 PM

Antony Blackett gravatar image

Antony Blackett
981 9 12 19

(comments are locked)
10|3000 characters needed characters left

Buy this plugin and all your problems are solved: http://u3d.as/content/databox-games/prefabs-in-prefabs-plugin/2Px

more ▼

answered Apr 11 '12 at 09:47 AM

JohanN gravatar image

JohanN
1

(comments are locked)
10|3000 characters needed characters left

If I interpret you correctly you need what I done recently.

I wanted to build in a single Prefab composed from several pieces: a bunch of grapes with 12 grapes, 2 leafs and 1 tip.

I went to the Scene and created the individual pieces, one by one (you can duplicate and rotate the grapes to change the appearance of them and also the leafs). I positioned them together to my convenience. Then went to Assets > Create > Prefab, which created a new empty prefab: I called it GrapesBunch. I shift-right-clicked each one of the objects in the Scene to have all them grouped. Then, GameObject > Make Parent. All the grouped objects formed a single entity. Drag the grouped objects from the Hierarchy windows to the new prefab icon (GrapesBunch) in the Project window. Then, I clicked on the GrapesBunch and I can swa all the parts of the prefab (each grape, each leaf, and so on)

I hope it help you.

more ▼

answered Apr 14 '11 at 03:00 AM

pepefirst gravatar image

pepefirst
30 11 14 21

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1256
x149
x130
x76
x61

asked: Apr 20 '10 at 12:07 PM

Seen: 8085 times

Last Updated: Apr 11 '12 at 09:47 AM