Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Managing nested prefabs

Discussion in 'General Discussion' started by jtsmith1287, Feb 10, 2015.

  1. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    So I know you can't have nested prefabs. My question is how people manage their scenes with just one layer of prefabs. For the game I'm creating every scene is pretty much the same. It requires a camera, light, various UI elements, etc. So every time I want to make a new scene I have to make sure I drag all these object into my scene. This takes like 4 seconds so whatever, no big deal. My issue though is that if I for any reason want to nest one of my prefabs under another, and click apply, it breaks the nested prefab. You absolutely can not parent any prefabs to each-other prior to runtime.

    So what are some workflows people employ to get around this or make things easier for themselves? I just have 6 or 7 objects I drag into every new scene, and then I spend a couple minutes attaching component references I know I'll need by default. It's not bad, but could obviously be a lot better.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,510
    Would it be possible for your needs to use empty game objects as the parent for your collection of prefabs, and then save that as a prefab?
     
  3. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Ya that would work fine. Do Empty Gameobjects not unlink prefabs that are parented to it?
     
  4. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Sorry, no. Doesn't work.
    For example:

    Directory/
    Prefab1
    Prefab2

    In Scene/
    Prefab1
    Prefab2

    If I click apply at any point on Prefab1, Prefab2 will unlink from its prefab in the Directory and any edits made to Prefab2 located in the directory aren't reflected on the one in the scene. I hope this makes sense. I don't need to have them parented in the directory, but I would like to be able to set them up in the scene the way I want and not break the dang prefab. So this is why I'm curious about other's workflows since I don't think my needs are too uncommon, and I'm imagining people have figured out a decent solution.
     
  5. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    Yeah, nested prefabs is the thing I miss the most in Unity.
    I also have multiple scenes (60) with a number of common objects. I ended up creating a massive prefab, with all the cameras, HUD, player model, etc.
    I've also created a separate scene, which I use to setup and edit that prefab.
    I've then created all the 60 scenes and added instances of that prefab to these scenes. I've edited instances in some scenes where they needed to be edited.
    If I then need to change something globally, for all the 60 scenes, I load my first "setup scene", make the necessary edits and hit apply.

    This approach works for me so far, but it's really easy to break something this way, so I would rather have proper prefab nesting.
     
  6. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    I started off with this approach. I broke everything multiple times and finally threw my hands up and broke everything into multiple prefabs.
     
  7. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    I use an approach similar to @Devil_Inside. I have one prefab called GameCore that has basically all my singletons. Anything that I only need one of per scene I put in that. One just needs to make sure they press apply for any changes, so as not to specialize the prefab instance.
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    For template scenes I set up exactly that - a scene that's just a template that I can load in the Editor and Save As the new scene I want to make. This has limitations, though, like not being able to change a common part of all scenes at once like you could via a prefab.