Search Unity

Nested Prefabs: Fully integrated, Completely automatic

Discussion in 'Assets and Asset Store' started by Visual-Design-Cafe, Mar 6, 2017.

  1. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    You can use the script in this post to remove all missing scripts from your project: https://forum.unity.com/threads/nes...mpletely-automatic.459495/page-5#post-3258696

    As for Playmaker. I tested Nested Prefabs with Playmaker FSM and everything seems to work fine. Do you have any more details about what the problem is?
     
  2. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    I've been testing the nested model system, it's neat that you can basically add components to nested FBXs.
    A big problem we experience in iterative production is modifying rigs.

    With base Unity we have to basically copy components that were added to the rig to a new copy

    With this Nested Prefabs system, it is effectively dependent on the hierarchy text path for adding components to FBX children. This is a problem because of any part of the hierarchy changes, eg a joint is renamed, moved up or down or removed then the added data is instantly lost.

    I just played around with the new Unity FBX Exporter (https://www.assetstore.unity3d.com/en/#!/content/101408)
    It has a very similar effect to Nested Prefabs nested FBXs, except it has a more reliable connection to gameObjects in a FBX hierarchy. They call it a Linked Prefab Instance. If you rearrange the hierarchy in Unity or Maya, and update the FBX it rearranges the gameobjects in the Linked Prefab Instance to match. Another feature over Nested Prefabs is you can easily modify the components that come with the FBX on import, like the Mesh Renderer's Material (which we do frequently).

    At this time I think we'll use the Unity FBX Exporter plugin for our nested models (but still nestin them using this Nested Prefabs system) because of that reliability reason.
     
    Last edited: Nov 14, 2017
  3. pdyxs

    pdyxs

    Joined:
    Sep 7, 2012
    Posts:
    6
    I've just started using this and am generally really liking it!

    However, often when I apply a prefab I get an error:

    Code (CSharp):
    1. Assertion failed: Assertion failed on expression: 'modifications.empty()'
    2. UnityEditor.PrefabUtility:InstantiatePrefab(Object)
    3. VisualDesignCafe.Editor.Prefabs.PrefabOperation:CreateInstanceForAsset(GameObject)
    4. VisualDesignCafe.Editor.Prefabs.PrefabOperation:GetInstanceForAsset(GameObject, Boolean)
    5. VisualDesignCafe.Editor.Prefabs.ApplyOperation:PreprocessPrefab(IPrefab)
    6. VisualDesignCafe.Editor.Prefabs.ApplyOperation:Do()
    7. VisualDesignCafe.Editor.Prefabs.NestedPrefabUtility:ApplyChanges(IPrefab[], Boolean)
    8. VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:ApplyPendingChanges()
    9. VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:EditorUpdate()
    10. VisualDesignCafe.Editor.PostprocessorEventDispatcher:OnEditorUpdate()
    11. UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
    It seems to save properly anyway, but it's always a bit worrying to get an error...
     
  4. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Unfortunately, we don't have the resources to build a similar system. Being able to keep the connection for each GameObject requires us to write a plugin for Maya (and 3ds Max, Blender, etc.), which at the moment is not a thing we can do. I'll look into the new FBX system to see if there are any improvements that we can implement in Nested Prefabs, but without additional plugins, there is a limitation on what we can do.
     
  5. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    This error is caused by Unity itself I am afraid. It usually happens if you have an Aspect Ratio Fitter component in your prefab. You can vote on this issue here: https://issuetracker.unity3d.com/is...prefab-which-has-aspect-ratio-fitter-attached

    To fix this you have to remove the Aspect Ratio Fitter components, though, you should be able to ignore the error. So far I haven't seen it cause any issues except for cluttering up the console.
     
  6. Try4W

    Try4W

    Joined:
    Mar 3, 2014
    Posts:
    4
    How can I remove or add a component for a specific instance of nested prefab?
    It seems that there is no way to override "adding new component" changes.
     
  7. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    It is not possible to add/remove a component for a specific instance at the moment. Instead, you can add the component to the original prefab and then override the "enabled" property of the component to enable/disable it for specific prefab instances.
     
  8. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    I haven't used their Maya plugin, I think there's enough info in a normal FBX from Maya (like a Maya a guid per node) for the Unity plugin to do it's work. But I don't really know what it's doing ¯\_(ツ)_/¯
     
    Last edited: Nov 20, 2017
  9. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    I post a Error with Playmaker , please Fix this !
    a.png
     
  10. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    I think this is the same thing I noted earlier, if you save the scene or reimport the asset I expect that the changes will propagate.
     
  11. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @thanhle, @jschroyen
    It should work fine if you save the scene after editing a prefab asset. But I'll look into it and see what I can find out.
     
  12. Alienniki

    Alienniki

    Joined:
    Nov 2, 2016
    Posts:
    7
    Save prefab attempt:

    The object you are trying to replace does not exist or is not a prefab.
    UnityEditor.PrefabUtility:ReplacePrefab(GameObject, Object, ReplacePrefabOptions)
    VisualDesignCafe.Editor.Prefabs.NestedPrefabUtility:ReplacePrefab(GameObject, Object, ReplacePrefabOptions)
    VisualDesignCafe.Editor.Prefabs.<>c__DisplayClass56_0:<AddContextMenuApplyAll>b__0(Object)
    UnityEditor.GenericMenu:CatchMenu(Object, String[], Int32)
     
  13. -Singularity-

    -Singularity-

    Joined:
    Jul 27, 2014
    Posts:
    122
    Hi, I'm getting this error a lot and it has the tendency to crash unity when occurring;

    Assertion failed: Assertion failed on expression: 's_AssetProgressBar.dialog'
    UnityEditor.AssetDatabase:StopAssetEditing()
    VisualDesignCafe.Editor.Prefabs.PrefabOperation:EndBatch()
    VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:ApplyPendingChanges()
    VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:EditorUpdate()
    VisualDesignCafe.Editor.PostprocessorCallbackProvider:OnEditorUpdate()
    UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

    I'm using Unity 2017.1.1f1 - any help appreciated
    Thanks
     
  14. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    That is a strange error. Can you send a screenshot of the prefab you are trying to apply, both the instance in the scene and the asset in the project view? It is possible that the prefab asset is no longer marked as a prefab by Unity, this can happen if Unity crashes during import.
     
  15. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    As far as I know, this error is caused by Unity itself. There has been a bug report about this in the beta forums as well. If possible, can you try to update to Unity 2017.2 to see if it is fixed in that version? I'll also look into it to see if maybe Nested Prefabs is causing this error to appear more often.
     
  16. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    Ive sent you a support email, please respond. cheers
     
  17. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
  18. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    Thanks for the helpful reply, Ive responded.
     
  19. -Singularity-

    -Singularity-

    Joined:
    Jul 27, 2014
    Posts:
    122
    Cheers, I'll give that a try and agree it's definitely related to unity itself. just doesn't happen with any other assets in my case.

    I'll report back
     
  20. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    I Post a big error make me remove Nested Prefabs
    I hope you can Fix it ..... i will come back use Nested Prefabs if the error have been fixed
    error.png

    you can download Gameobject.prefab in attach file
     

    Attached Files:

  21. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    I've had issues with Playmaker and prefabs not saving playmaker references propperly in the past, make sure you have the most recent version of Playmaker just in case
     
  22. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Thank you for the detailed description of how to reproduce this issue. I have looked into it and had the same result, however, I can confirm that it has nothing to do with Nested Prefabs and is caused by Playmaker. The exact same issue happens without Nested Prefabs installed. It will be best to contact the developers of Playmaker and ask them if they can fix this.
     
  23. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    Thank you let me try with new version playmaker !
     
  24. Ozone3000

    Ozone3000

    Joined:
    Jan 11, 2017
    Posts:
    1
    I think I have a bug.
    If I duplicate a prefab, and then create a new prefab from that duplicate (both of these are nested).
    Then some changes to the original prefab are being applied to the new prefab.
     
  25. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    This is new test with Playmaker (Latest version )
    and i think this is not error by playmaker
    Please check it !
    a.png
     
  26. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @thanhle
    I have looked into the problem again and I can confirm (again) that this has nothing to do with Nested Prefabs. The exact same thing happens when Nested Prefabs is not installed.

    I strongly recommend contacting the developers of Playmaker to ask about this issue with prefabs.

    Please take a look at the following screenshot to see the same result without Nested Prefabs:
    FSM_No_Nested_Prefabs.jpg
     
  27. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Can you share a screenshot of your prefab setup and which changes are being applied? I can't seem to reproduce the issue you are describing.
     
  28. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    Thank you !
    My bad i will contact with playmaker fix about it !
     
  29. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    Make sure both of you are editing the Prefab, and not the Prefab Instance, there's a notice at the top of the State's actions, click Edit Prefab.
     

    Attached Files:

    Last edited: Nov 26, 2017
  30. thanhle

    thanhle

    Joined:
    May 2, 2013
    Posts:
    162
    i click to "Edit Prefab" but it just work in the prefab only .... object in scene still not work!
    i posted the error in here : http://hutonggames.com/playmakerforum/index.php?topic=16188.0
    Hope they will Fix soon !
     
  31. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    I would like to know if there are plans to improve performance as some users are complaining about that and I noticed that my project takes a bit longer to compile just by having 5 or 6 prefabs in the scene.
     
  32. BazookasZerreth

    BazookasZerreth

    Joined:
    Dec 8, 2016
    Posts:
    17
    We're very happy with the plugin and the support on it so far and we're using it now in all of our projects. (together with your SVN plugin.) However we've encountered twice now that when we update the nested prefab plugin to the latest version some prefab overrides get deleted. So we've taken the stance to only update when absolutely needed.

    For example we have modular buildings that use prefab overrides to set the material. These material overrides get deleted when we update the plugin. We've had the same issue with some overrides that got deleted on UI elements that also heavily use nested prefabs. ( Content Size fitter > Enabled, Layout Element > left, right margins, etc... )
     
    Last edited: Dec 7, 2017
  33. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    The last time the developer replied was like 2 weeks ago.... I thought I was buying a bug free asset that was ready to go but now hearing people complaining that it started deleting stuff and bugging out isn't good news. I bought it during the sale and haven't even used it yet.
     
  34. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Im pretty happy with updates and time it save, i also used others and found this implementation is the best, author usually reply on time and provide timely updates to bugs but seems like he must be busy somewhere, hopefully he will reply sooner.
     
  35. holyshovelsoft

    holyshovelsoft

    Joined:
    May 23, 2017
    Posts:
    1
    Hi all. I download trial of this asset and I have one question. If I have (in custom component) some complex type field (struct with some fields inside) how I can create override for all field, not per inside fields? The same question with arrays,vectors, quaternions, uinity events and other complex types... Its sad, but I dont find correct way do this.
     
  36. AmbroiseRabier

    AmbroiseRabier

    Joined:
    Dec 4, 2016
    Posts:
    14
    Hello, I have a problem with Nested Prefabs, I am missing something I think.
    Look at the screens:

    upload_2017-12-13_12-16-34.png

    Break prefab connection:
    upload_2017-12-13_12-17-0.png

    I broke the prefab connection on the UI object. How do I fix the GameOverScreen? I want it to be a normal prefab again.
    In my Assets, I have a UI prefab and a GameOverScreen prefab.

    What I would like to see:
    upload_2017-12-13_12-21-13.png

    How can I achieve this?
     
  37. Shinono23

    Shinono23

    Joined:
    Dec 25, 2016
    Posts:
    5
    Hello! Whenever you get back, I have a suggestion.

    Let's say I have 2 prefabs for 2 different characters.

    They share a body prefab (with skeleton for animation) so I don't have to keep mirroring changes to them by hand.

    What if on one skeleton prefab's head bone, I want to have a hat prefab and on the other I want a visor prefab?

    Currently if I click apply on one, they'll wear the same thing on their heads, because it's applied as a child prefab of the skeleton and not the people prefabs.

    Is there any way you can add prefabs to the prefab overrides script? or is there a way to do this already? Without this functionality, this plugin can't be used for characters that share a common body and wear different prefab clothing or attachments (especially unrigged).
     
  38. SilverStorm

    SilverStorm

    Joined:
    Aug 25, 2011
    Posts:
    712
    Waiting 1 month without a response I am not getting the best vibes. I hope this guy isn't dead or something?
    Anyone have any news?
     
  39. inkyphilospher

    inkyphilospher

    Joined:
    Aug 26, 2014
    Posts:
    13
    It's the holiday season, he's probably taking some time off, give it some time :)
     
  40. chenm

    chenm

    Joined:
    Mar 8, 2016
    Posts:
    1
    Hello,
    I'm using unity: PrefabUtility.CreatePrefab(...)
    But it seems that nested prefabs does not process such action thus the result prefab has no nested prefabs in it, the only prefab it the root containing prefab which was the one saved.

    Is there any support for creating a prefab from script?
    Thanks
    Chen
     
  41. DigitalJim

    DigitalJim

    Joined:
    Apr 16, 2015
    Posts:
    2
    Hi,
    We have been using Nested Prefabs, but have had a few issues. Hopefully you can help.
    1. Applying changes to a prefab, causes files of any prefabs that contain it to change. This has created a nightmare for us when using version control as a tweak to change the style of a button prefab causes every prefab that uses said prefab to change and then require this creates a huge amount of conflicts in git. (having TextMeshPro serializing things like the current font size of the dynamically sized text didn't help matters)
    2. Game objects sometime change sibling order on load, I have a feeling it is nested prefabs as this is the only reference I could find to the issue https://answers.unity.com/questions/1156732/objects-in-hearachy-change-order-for-no-reason.html. And it seems to even affect a scene that has a regular prefab but does not contain a nested prefab. It seems to be on load as I have inspected the yaml and the order was serialized correctly.
    3. The fact that clicking the apply button in the inspector or creating a new prefab from an object that contains prefabs causes all the child prefabs to have their values be applied to their source prefab. This gets dangerous as the apply as undo won't fix the mistake.
    We would love to keep using this but if these issues persist we will have no choice but to drop it.
    Do you think you could help us out?
     
  42. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Happy New Year everyone! We just got back from our holiday vacation.
    Our apologies for the late replies, it seems the forum notifications were no longer sent and we didn't double check the latest posts due to the holiday season. We'll answer all your questions as soon as possible!
     
  43. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    We have some performance improvements ready for the next update (1.3.0). In your case, you mention that the compile time increases. Do you mean the script compile time? Script compile time should not increase at all, only the apply time of prefabs. If the compile time increases, you can move the Nested Prefabs folder into the Plugins folder so that Unity does not have to recompile the plugin, that should save some compile time.
     
  44. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Thank you for using both our assets :)
    That's very strange, we specifically check that no data goes missing between updates. Do these overrides go missing immediately after updating the plugin or after making some changes and/or updating/committing to SVN?
    Also, what kind of data goes missing? Is there any specific data type that has issues or is it seemingly random?
     
  45. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Yes, you can create nested prefabs through script but it requires some additional actions. You have to make sure that all prefabs are saved before nesting them and you have to make sure to use ReplacePrefabOptions.ConnectToPrefab when creating the prefabs.
    For example:
    Code (CSharp):
    1. var nestedPrefabA = new GameObject();
    2. PrefabUtility.CreatePrefab( "Assets/NestedPrefabA.prefab", nestedPrefabA, ReplacePrefabOptions.ConnectToPrefab );
    3.  
    4. var nestedPrefabB = new GameObject();
    5. PrefabUtility.CreatePrefab( "Assets/NestedPrefabB.prefab", nestedPrefabB, ReplacePrefabOptions.ConnectToPrefab );
    6.  
    7. // Save the prefabs so that they can be processed by the plugin to prepare them for nesting.
    8. AssetDatabase.SaveAssets();
    9.  
    10. var rootPrefab = new GameObject();
    11. nestedPrefabA.transform.SetParent( rootPrefab.transform );
    12. nestedPrefabB.transform.SetParent( rootPrefab.transform );
    13. PrefabUtility.CreatePrefab( "Assets/RootPrefab.prefab", rootPrefab, ReplacePrefabOptions.ConnectToPrefab );
     
  46. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Vectors, Rect, and Quaternions can be overridden entirely, all others have to be selected individually. This is because the properties are serialized separately by Unity. I'll see if I can add a shortcut to the prefab overrides popup to add entire structs with a single click. Right now the easiest way to do this is to go to the 'modified properties' tab and select all the properties in the struct (only possible if they are modified).
     
  47. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Unfortunately, this is not possible easily. Unity can't completely remove a prefab connection so even when breaking the connection of the root prefab it remains a prefab. It is also not possible to only have a part of the prefab hierarchy connected. As a result, it is not possible to reconnect the GameOverScreen here because it would result in only a part of the prefab hierarchy being connected.

    A workaround is to drag the GameOverScreen out of the UI prefab first, then break the UI prefab connection, and then reparent the GameOverScreen so it is a child of the UI prefab again.
     
  48. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    1. Unfortunately, this is a limitation of our nested prefab solution and Unity because nested prefabs is not supported by Unity. The prefab system in Unity only supports having a single prefab. In order to have all the nested prefabs show up in the hierarchy and making them editable, we have to store a copy of the nested prefab data in the root prefab. Whenever you edit the original prefab, all copies of the data have to be updated wherever the prefab is nested. There is no workaround for this and it is the core of our nested prefab solution. So, unfortunately, this is a limitation that will stay :(

    2. This should not be caused by Nested Prefabs. The plugin is disabled completely at runtime and only modifies serialized data. So, if the changed order is not visible in the serialized (YAML) data then I can't think of any reason how Nested Prefabs would be able to change the order.

    3. Currently, this is the workflow that we have chosen for because it is the most stable. If the values are not applied to the source prefabs immediately then there will be inconsistent property values throughout the project, which can cause confusing results. We currently do not have any plans to change this approach as we feel that stability has the highest priority for the plugin.
     
  49. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Unfortunately, this is not supported at the moment. Though, it is planned to be added in the next update (we are currently working on it)
     
  50. chillypacman

    chillypacman

    Joined:
    Oct 1, 2011
    Posts:
    71
    Hey There!

    I'm very interested in this plugin and decided to give the free trial a run as a test case.

    Overall the functionality is very good and does what I want, however I think there's some weird performance issues.

    I had a prefab with two nested prefabs and when I hit 'apply' anywhere on the prefabs in the scene regardless if I had changes or not unity would lock up for a while. It's also incredibly slow when I simply right click on the prefab icon for a prefab in the scene so I don't think this is normal behavior.

    The profiler shows nothing that I can tell is related to Unity prefabs and CPU usage doesn't become abnormally large..

    I'm currently using Unity 2017.3.0f3 free version.

    After removing and re-adding the nested prefabs the issues went away.

    I got the following error and warning when hitting apply but not when right clicking on the prefab icon in the scene hierarchy so it might not be related:

    Is this a known issue or could I have done something incorrectly which caused this? Anyway to diagnose these issues?

    I'm really keen on using this plugin but don't want to commit to something that will impact my workflow so negatively..


    edit: Upon further investigation I found the issue could be to do with a certain gameobject which has a lot of children (not nested just flat but stored in a nested prefab). Upon removing this gameobject performance improved.

    So it looked like this:

    [Nested Prefab]
    -> GameObject
    ----> [hundreds of gameobject children]

    Is there a way to deal with this sort of thing?
     
    Last edited: Jan 7, 2018