Search Unity

Poor mans nested prefab

Discussion in 'Scripting' started by copenhagenjazz, Nov 16, 2013.

  1. copenhagenjazz

    copenhagenjazz

    Joined:
    Oct 2, 2005
    Posts:
    45
    Hi there

    So I saw this blog post from Nicholas F; http://framebunker.com/blog/poor-mans-nested-prefabs/

    Thats pretty exciting.

    However I cant really seem to get it working :(

    Can someone walk a scripting noob through the process from A-Z.

    Is it a C# script or Java? I have tried doing it as a C# script but then I cannot apply it to my game objects. When applied as a Java script I cant really seem to figure out the functionality.

    Any help on the subject would be greatly appreciated :)

    Thanks
     
  2. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    It is C# code.
    What errors are you getting when you try to apply it to your GameObjects?
     
  3. copenhagenjazz

    copenhagenjazz

    Joined:
    Oct 2, 2005
    Posts:
    45
    Hmm well now I managed to add the component as a new C script to my object. However I am sort of clueless of how this script actually works - ? How do I assign the prefabs to the "master" prefab? Should all prefabs used in the setup have the script assigned?

    I also get this error message on the scipt component on my prefab; The associated script cannot be loaded. Please fix any complie errors and assign a valid script".

    This of course indicates I have done something quite wrong - I just dont know what.

    Sorry for being such a clueless art git but I am trying my best :)

    Thanks
     
  4. copenhagenjazz

    copenhagenjazz

    Joined:
    Oct 2, 2005
    Posts:
    45
    Still no takers? :)
     
  5. flaviusxvii

    flaviusxvii

    Joined:
    Dec 20, 2010
    Posts:
    9
    Make a file called PrefabInstance.cs and put it under Assets/Editor/ somewhere.

    Then make an empty gameobject. Add a "Prefab Instance" component to it. It has a public attribute called "prefab". Choose a prefab from your assets and put it in there. Now this new gameobject you made should look like the prefab it is pointing at. At run-time, it'll make an instance of that prefab.
     
  6. copenhagenjazz

    copenhagenjazz

    Joined:
    Oct 2, 2005
    Posts:
    45
    Thank you so much for your answer :)

    However I cannot seem to be able to find and add the "Prefab Instance" component to my game object - ? I made the PrefabInstance.cs and put it in the editor folder but I have no Prefab Instance component available it seems. Any idea why?

    Thanks again
     
  7. copenhagenjazz

    copenhagenjazz

    Joined:
    Oct 2, 2005
    Posts:
    45
    Hi again

    Alright I now managed to get it working and thought I just wanted to share how I did it in case anyone was having similar issues. Aside from adding the PrefabInstances.cs to your Assets\Editor\ folder you also need to add it to another folder in your project. Personally I have a folder just called scripts where I made another PrefabInstances.cs.

    Now it is possible to add the prefab instance component to your prefabs.

    Most excellent :)
     
  8. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    I have also develop some nested prefab solution, and you can test for free. Download Packege