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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Nested Prefabs: Fully integrated, Completely automatic

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

  1. Sarudan

    Sarudan

    Joined:
    May 21, 2011
    Posts:
    65
    Is there a possibility of asking the user during installation if they want to just reimport the models or do a full reimport?
     
  2. Alienniki

    Alienniki

    Joined:
    Nov 2, 2016
    Posts:
    6
    I updated new version 1.2.2
    Unity crashed after next manipulation:
     

    Attached Files:

  3. Alienniki

    Alienniki

    Joined:
    Nov 2, 2016
    Posts:
    6
    Next
     

    Attached Files:

  4. Alienniki

    Alienniki

    Joined:
    Nov 2, 2016
    Posts:
    6
    After add plugin, Nested Prefabs scans all folders on project. Can I specify to scan a specific folder? We use nested prefabs to UI only
     
  5. TeamHoray

    TeamHoray

    Joined:
    Dec 21, 2015
    Posts:
    7
    How to change "Sorting Layer & order" of Sprite Renderer on Prefab Overrides?
     
  6. TeamHoray

    TeamHoray

    Joined:
    Dec 21, 2015
    Posts:
    7
    And I can't change the size of array on Prefab overrides.
    I want to change the size of array(also all elements of array). Is it possible?

    upload_2017-7-2_21-57-9.png

    2017-07-02.png
    2017-07-02 (1).png
     
  7. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    No, it is not possible at the moment. I'll look into the install process to see if I can speed it up for large projects. But I am afraid it won't be available until the next release so you won't be able to speed it up now.

    @Alienniki
    I am looking into the crash issue for you, is there any possibility that I can access the project or the prefabs that cause the crash?

    No this is not possible, the plugin has to be installed for all folders for stability and consistency purposes.

    @Gaemi_Ahn
    I just checked it for you and it is not possible. Unity has hidden the properties by default so they don't show up. I'll manually add them to the list for the next update. If you need them added right now and can't wait for the next release then please send me a PM and I'll send you a custom build.

    This is not yet supported I am afraid. It is on the feature list for a next update, I'll give it a higher priority since I understand it can be quite limiting to not being able to override the size of an array.
     
  8. vincentgravitas

    vincentgravitas

    Joined:
    Jan 25, 2015
    Posts:
    6
    @Visual-Design-Cafe,
    I've been trying the Nested Prefabs demo, and as a longtime Prefab Evolution user, your solution is a hundred times easier to use and understand, and takes a fraction of the time to do its bookkeeping. Even though PE's override system is very surgical, it's confusing and overblown. Yours is straightforward and I can get to that.

    Unfortunately, I can't get the prefab overrides to work at all. They dirty the values on the instance and the prefab when applying -- it's the same as before, not using overrides. I have tried overriding properties of different component types (MonoBehaviour and Animator) and both have the same problem. What am I doing wrong?

    I'm following your crystal clear instructions from this documentation: https://www.visualdesigncafe.com/products/nestedprefabs/documentation/#overrides

    And checking this thread for help on usage, I still can't figure out why I can't get it to work. Any help is appreciated. I'm using Unity version 5.6.1f1.
     
    Last edited: Jul 8, 2017
  9. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @Appelsindrikken
    Thank you for trying out Nested Prefabs and I am glad you like it so far. I have sent you some additional explanation about the Prefab Overrides as well as an example by email. Please take a look at it and let me know if you have any further questions.
     
    vincentgravitas likes this.
  10. vincentgravitas

    vincentgravitas

    Joined:
    Jan 25, 2015
    Posts:
    6
    This is very strange. I tested the prefabs you gave me and they are working fine and exactly how I would think they should.

    For some odd reason, this problem is only happening with my own prefabs. I will have to troubleshoot this a little more and see what the matter is. I'll reply here as soon as I have something.
     
    Visual-Design-Cafe likes this.
  11. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Version 1.2.3 of Nested Prefabs has just been submitted to the Asset Store! For everyone who has version 1.2.1 or later, you can download the new version directly through the in-editor download window which should show automatically the next time you open Unity.

    If you have ever experienced any crashes caused by Nested Prefabs then it should be fixed now in this new version. Some edge case issues with object references have also been fixed. For a complete list of changes please check the changelog.
     
    vincentgravitas and tapawafo like this.
  12. vincentgravitas

    vincentgravitas

    Joined:
    Jan 25, 2015
    Posts:
    6
    It's working now! I deleted the nested prefab from its parent (broke parent prefab connection), added the nested prefab again, applied all prefab changes on parent (this reconnected parent prefab), added override component + override rule to the nested prefab and pressed apply all on the parent.

    If I encounter this issue again, I'll let you know right away, and hopefully with a clue.
     
  13. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @Appelsindrikken
    Glad to hear it is working now. I have never received any report of an issue with the prefab overrides so if you do encounter this again then please let me know. If there is even the smallest error then I'll do my best to fix it.
     
    vincentgravitas likes this.
  14. mikemonroe_oc

    mikemonroe_oc

    Joined:
    Dec 7, 2016
    Posts:
    4
    I started using this, and this is almost perfect. However there's a semi-frustrating disconnect with how some of the changes to prefabs get propagated. For example if I edit a prefab (that's nested somewhere) via the Project + Inspector view the changes won't show up in the nested prefabs in the scene until Unity actually writes those changes to disk (via saving or quitting Unity).
    Is there any way to fix this? It mostly makes me very paranoid about if my changes are appearing or not.
     
  15. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Unfortunately, when editing assets directly in the project view the only way to apply the changes is to save the scene/prefab. This is because Unity does not have any reliable callback for changes made to the prefab before saving.
    There is one callback, however, it only gets called if the prefab is also in the scene. Because of this, I have decided to not use it as it will make applying changes to assets very inconsistent. I will see if I can find a way to make applying changes easier, maybe with a custom apply button.
     
    laurentlavigne likes this.
  16. shadowsora

    shadowsora

    Joined:
    May 21, 2013
    Posts:
    5
    Hi!

    I've just tried out your tool, because I really do think I need nested prefabs for my project and this tool looks like the easiest to use out of the ones available on the market. However there seems to be a problem.. If I have prefab that is nested in the scene, and I change a parameter value in the equivalent prefab in the assets folder, it doesn't update the value in the nested prefab? This is confusing because isn't this kinda the point of keeping the references? So that if I need to change a prefab it will update all of the other instances, including the nested ones?

    Hope to hear back from you! :)
     
  17. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @shadowsora
    Thank you for your interest in Nested Prefabs. If you change a prefab asset you have to save it in order to apply the changes. The easiest way to do this is to simply save the scene and then Unity will save all modified prefab assets as well.
     
  18. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    For everyone who is planning to upgrade to Unity 2017: Nested Prefabs has been tested and works fine in Unity 2017. There is no need to take any additional steps in order to continue using Nested Prefabs in Unity 2017, you can keep the same version of Nested Prefabs that is already installed in your project.
     
  19. VelociraptorGames

    VelociraptorGames

    Joined:
    May 28, 2017
    Posts:
    2
    I cannot seem to set the Lightmap scale via overrides.

    So if I want to refer to a model and override the lightmap scale then the parameter isn't available under mesh renderer component via the prefab override. This is kinda critical. The only other option I see is to rebuild the object manually via mesh filter & renderer, but this kind of defeats the purpose of using the auto gerenerated models entirely from meshes. Plus you need to refer to the Models when using skinned meshes. So this is mostly a problem for static meshes. Any Advice ?

    Setting the original model to lightmap static and changing lightmap scale has little use because that is reset everytime you reimport the mesh. :(
     
    Last edited: Jul 24, 2017
  20. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @VelociraptorGames
    I have looked into it for you and the lightmap properties are marked as internal properties by Unity and are therefore not shown by default in the overrides list. I have added them to the custom list of additional properties that should be possible to override. The static flags are also ignored now when reloading the nested model prefab from the original asset, so you can set those for each nested model prefab separately. I'll send you the latest build with these changes once it is ready (should only take a couple of hours).

    If you come accross any other properties that are not shown in the overrides list then please let me know and I'll add them as well.
     
  21. v-line

    v-line

    Joined:
    Feb 13, 2013
    Posts:
    10
    The asset is really cool. And saves a lot of time.

    We are planning to start using a version control app. Currently we are thinking if we want to use github, bitbucket, plastic scm or tfs. Has anyone tested how does Nested Prefab work with any of them?
     
  22. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @v-line
    Glad to hear you like nested prefabs! The plugin should work just fine with version control. It has been developed while using SVN (Subversion) but it should work with other version control solutions as well.
     
  23. piojox11

    piojox11

    Joined:
    Jul 16, 2015
    Posts:
    13
    Hey, I'm using the trial, version 1.2.3.30 (will buy this afternoon if a few more tests go smoothly), and wanted to report a bug. I'm on Unity 5.6.2.

    I started with a scene object which is a prefab instance. I made it a nested prefab by dragging a child object (which itself has children) into the hierarchy. I selected the new child prefab in the hierarchy. I disabled one of its children and saved the project. Test result: success, because the corresponding object became disabled. I re-enabled the nested prefab's child and saved the project, but the corresponding scene object did not become re-enabled. The change was picked up when I disabled/renamed any object--it seems as though changes are noticed and applied properly, but the system won't see an object becoming enabled as a change, if there are no other changes.

    In short, if you start with this scene object A (and corresponding prefab A'):
    A
    |- B
    |- C
    |- D

    Drag B into the hierarchy to create prefab B'. Disabling C' will correctly cause C to be disable, but re-enabling C' will not re-enable C, unless another more significant change is also made somewhere in the B' prefab.
     
  24. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @piojox11
    Thank you for your interest in Nested Prefabs. I am not sure if I completely understand which changes you are trying to make to the prefab (it can get complicated really quickly when trying to explain nested prefab hierarchies ;)).

    There are a few things you should pay attention to when editing the active state of an object:

    1. The active state of a nested prefab is saved in the parent prefab. In the example screenshot "Prefab B", "Prefab C" and "Prefab D" are nested prefabs and can be enabled/disabled individually, without the active state being applied to the prefab asset. Any children within these nested prefabs (such as "Prefab A/Prefab B/Child") will have their active state applied to the original prefab like expected.


    2. When editing a prefab directly in the project view + inspector (editing the asset, not an instance), the prefab has to be saved first in order to apply the changes. You can do this by saving the scene or reimporting the prefab.

    If the above two cases do not apply to the situation you described then please share a screenshot of the prefab setup with me and I'll look into it.
     
  25. paulomuggler

    paulomuggler

    Joined:
    Mar 18, 2014
    Posts:
    4
    I'm facing basically the same as @igor84, here, that there is one property that's different in every instance of a prefab, which is some text. I tried adding a PrefabOverrides component to the prefab itself, so that I have it automatically created on any instances, and it is already set to the overriden property, saving me the time, effort and chance of error by not having to add and setup a PrefabOverrides every time I create a new instance of the prefab. Then all I would have to do for each instance would be to set its value accordingly, which sounds intuitive to me.

    When I add a PrefabOverrides component it does not seem to carry over to instanced prefabs on the scene, is that the expected behavior? Or am I doing something wrong?

     
  26. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    It sounds like you are trying to add a PrefabOverrides component to a root prefab (the original asset of a nested prefab), which is not supported. It is only possible to add the component to a nested prefab.

    The easiest way to have a different value for each instance is to simply change the value and not apply it. If it has a bold font in the inspector it is overridden (same as the regular Unity prefab system) and will not load its value from the original prefab. However, if you apply the prefab then the value will be applied as well.

    If you need an easy way to ignore a property for all nested prefabs you can use the following script and add your component and ignored properties to the IgnoredProperties dictionary (replace "MyComponent" and "AlwaysOverriddenPropertyB"):
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.Linq;
    3. using UnityEngine;
    4. using VisualDesignCafe.Editor.Prefabs;
    5.  
    6. [CustomProcessor( typeof( IPrefab ) )]
    7. public class MyComponentProcessor : MonoBehaviour
    8. {
    9.  
    10.     /// <summary>
    11.     /// Collection of all ignored properties for each component.
    12.     /// </summary>
    13.     public static readonly Dictionary<System.Type, string[]> IgnoredProperties = new Dictionary<System.Type, string[]>()
    14.     {
    15.         {
    16.             typeof(MyComponent),
    17.             new string[]
    18.             {
    19.                 "AlwaysOverriddenPropertyB",
    20.             }
    21.         },
    22.         {
    23.             typeof(MyOtherComponent),
    24.             new string[]
    25.             {
    26.                 "AnotherAlwaysOverriddenPropertyB"
    27.             }
    28.         },
    29.     };
    30.  
    31.     /// <summary>
    32.     /// Gets called after all modifications to a prefab have been found and before applying them.
    33.     /// Removes all properties that are in the IgnoredProperties dictionary from the modification list.
    34.     /// </summary>
    35.     public static Modification[] PostprocessModifications( IPrefab prefab, Modification[] modifications, IPrefab source )
    36.     {
    37.         return modifications.Where(
    38.             m =>
    39.             {
    40.                 // Include all modifications other than "PropertyValueChanged".
    41.                 if( m.Type != ModificationType.PropertyValueChanged )
    42.                     return true;
    43.  
    44.                 // Include all modifications that are not to a component in the IgnoredProperties dictionary.
    45.                 string[] properties;
    46.                 if( !IgnoredProperties.TryGetValue( m.SourceObject.targetObject.GetType(), out properties ) )
    47.                     return true;
    48.  
    49.                 // Include all modifications that are not in the list of ignored property paths for the component.
    50.                 if( !properties.Contains( m.SourceProperty.propertyPath ) )
    51.                     return true;
    52.  
    53.                 // Remove the property from the modification list.
    54.                 Debug.Log( "Ignoring changes to " + m.SourceObject.targetObject.GetType() + "." + m.SourceProperty.propertyPath );
    55.                 return false;
    56.  
    57.             } ).ToArray();
    58.     }
    59. }
    60.  
     
  27. piojo9

    piojo9

    Joined:
    May 29, 2015
    Posts:
    10
    @Visual-Design-Cafe Thanks. I can't reproduce it on that simple example. If I remember the exact scenario, I'll send you a better test case.

    I found a more serious problem, though--it seems like we need an option for manually re-caching the prefabs. After some changes, a revert, and reverting the revert, all my project's prefab links seem to be broken. Not the Unity links, but the Nested Prefab links. As you can see in the screenshot, it's the root that has the problem. On disk, the files are kosher--the repository is in the same state as yesterday (except for some added files), when Nested Prefabs was working. Note that in this state, dragging LoadManagers.prefab into the scene again forms another missing prefab rather than a correct one.

    It seems easy to get into this corrupt state, though I'm not sure how it happens each time. Restarting Unity does not help. I triggered the "Caching prefabs" operation somehow (by dragging a "missing" prefab into the hierarchy), and it fixed all the prefabs but one. The problem returned, though. Until this is fixed, can you send me the code that will trigger a full re-cache? I can put it in a menu item.
    missing-prefab.PNG

    (Edit: removed a workaround that doesn't actually work.)
     
    Last edited: Aug 3, 2017
  28. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @piojo9
    Did you revert any changes to the prefab in the repository? It looks like the stored asset GUID got reverted or removed. Also, please make sure the meta files of your assets are also stored in the repository. Unity might have regenerated the meta files, giving the prefabs a new GUID.

    If only the root prefabs have this issue then you should be able to fix it easily by reimporting the prefabs that have a missing reference. Reimporting will save the asset GUID for each prefab again.

    Updating the internal cache shouldn't have any effect in this case, as the cache does not store the prefab GUID values.
     
  29. piojo9

    piojo9

    Joined:
    May 29, 2015
    Posts:
    10
    @Visual-Design-Cafe Thanks. Reimporting the prefab temporarily fixes it, but it displays as missing when Unity is next restarted. Reimporting caused these five lines to be removed from the prefab:

    _prefab: {fileID: 0}
    _cachedParentPrefab: {fileID: 0}
    _isCached: 0
    _hasPrefab: 0
    _parentPrefab: {fileID: 0}

    And I also noticed the _guid field seems longer than it should be, compared to a similar _guid field in other files. I'm almost sure that's the problem. In SceneManager.prefab, I look through the commit history and see that when Nested Prefabs auto-modified it, it removed those five lines, and changed a long _guid to a shorter _guid. That change did not happen in the prefabs that are experiencing the problem, and reimporting changed the five lines above without changing _guid.

    Edit: It looks like I didn't commit the scene files, and that part of the change got wiped out. That doesn't really explain the problem (for example, the prefabs with problems could not be dragged into the scene to create properly linked prefabs), but at least I can fix it.
     
    Last edited: Aug 3, 2017
  30. piojo9

    piojo9

    Joined:
    May 29, 2015
    Posts:
    10
    The uninstall/reinstall process seems to have only fixed the prefabs that had instances in the currently opened scene. Prefab links in other scenes are still "missing"--unless of course, they did have an instance in the currently opened scene.

    (So before, I said I missed .unity files when committing changes--that fact seems irrelevant, if only the Nested Prefabs will be broken for prefabs which aren't in the current scene at the time the plugin is installed. This is surely a bug in the installation process.)

    I can't reproduce this on a little toy project, though.

    Edit: It's some prefabs, not all. It seems like those that were already in the scene are failing, but those that only existed as lone prefabs are succeeding. I guess the installer added some data which could not successfully percolate into scene objects for closed scenes.
     
    Last edited: Aug 3, 2017
  31. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @piojo9
    I just tried to reproduce this issue but I can't seem to find any issue with the prefabs or the installation process.

    Where did you find this data? Those properties are not serialized so they should not be saved by Unity. The serialized data of a prefab component looks like this (see screenshot). The GUID for the asset is stored in "_assetGuid", which is the value that is incorrect for the prefabs with the red "X" on the icon. Can you check if either this value or the meta file of your prefab changed?
    serialized_prefab_data_assetguid.jpg

    Can you also let me know which version of Unity you are using, what kind of version control you are using and your version control settings (Asset Serialization and Version Control Mode in Edit/Project Settings/Editor)?
     
  32. piojo9

    piojo9

    Joined:
    May 29, 2015
    Posts:
    10
    @Visual-Design-Cafe Before I investigate and answer those questions, I can add another detail--
    If I get into a state where "missing prefab" is displayed and reimporting the prefab fixes it only until Unity is restarted, the solution is to force the prefab to be saved, even though Unity doesn't want to--change its properties, save, change back, save. At first I thought you forgot to call EditorUtility.SetDirty() on the prefab, but it looks weirder because I can see the prefab was changed the first time around, but it wasn't changed *enough*. When I do "reimport" and change a property, I see additional changes related to Nested Prefabs.
     
  33. piojo9

    piojo9

    Joined:
    May 29, 2015
    Posts:
    10
    @Visual-Design-Cafe My asset serialization is set to force-text. I'm using Git. Unity 5.6.2 on Windows. Here are two diffs--the problem and the fix.

    When I first installed Nested Prefabs, this is the change that happened to a prefab (which subsequently was shown as missing):

    --- a/Assets/Data/GamePrefabs/Misc/LoadUIManager.prefab
    +++ b/Assets/Data/GamePrefabs/Misc/LoadUIManager.prefab
    @@ -5,10 +5,12 @@ GameObject:
    m_ObjectHideFlags: 0
    m_PrefabParentObject: {fileID: 0}
    m_PrefabInternal: {fileID: 100100000}
    - serializedVersion: 4
    + serializedVersion: 5
    m_Component:
    - - 4: {fileID: 400000}
    - - 114: {fileID: 11400000}
    + - component: {fileID: 400000}
    + - component: {fileID: 11400000}
    + - component: {fileID: 114010671839222354}
    + - component: {fileID: 114792902660235394}
    m_Layer: 0
    m_Name: LoadUIManager
    m_TagString: Untagged
    @@ -27,6 +29,8 @@ Transform:
    m_LocalScale: {x: 1, y: 1, z: 1}
    m_Children: []
    m_Father: {fileID: 0}
    + m_RootOrder: 0
    + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
    --- !u!114 &11400000
    MonoBehaviour:
    m_ObjectHideFlags: 1
    @@ -50,4 +54,46 @@ Prefab:
    m_ParentPrefab: {fileID: 0}
    m_RootGameObject: {fileID: 100000}
    m_IsPrefabParent: 1
    - m_IsExploded: 1
    +--- !u!114 &114010671839222354
    +MonoBehaviour:
    + m_ObjectHideFlags: 1
    + m_PrefabParentObject: {fileID: 0}
    + m_PrefabInternal: {fileID: 100100000}
    + m_GameObject: {fileID: 100000}
    + m_Enabled: 1
    + m_EditorHideFlags: 0
    + m_Script: {fileID: -605777808, guid: 325c5b2a7434372429c2ca9d61dba58e, type: 3}
    + m_Name:
    + m_EditorClassIdentifier:
    + _isConnected: 1
    + _guid:
    + _referenceCollection:
    + _prefab: {fileID: 114010671839222354}
    + _collection:
    + - {fileID: 100000}
    + _hasCachedValidation: -1
    + _cachedGetIsValid: 1
    + _assetGuid: 3562343739333530613537303834366635383061393934376333306565313430
    + _cachedAsset: {fileID: 0}
    + _cachedAssetGuid:
    + _cachedObjectGuid: {fileID: 0}
    + _cachedTransform: {fileID: 0}
    + _cachedGameObject: {fileID: 0}
    + _cachedRoot: {fileID: 0}
    +--- !u!114 &114792902660235394
    +MonoBehaviour:
    + m_ObjectHideFlags: 1
    + m_PrefabParentObject: {fileID: 0}
    + m_PrefabInternal: {fileID: 100100000}
    + m_GameObject: {fileID: 100000}
    + m_Enabled: 1
    + m_EditorHideFlags: 0
    + m_Script: {fileID: 112998890, guid: 325c5b2a7434372429c2ca9d61dba58e, type: 3}
    + m_Name:
    + m_EditorClassIdentifier:
    + _guid: 62323337393639362d383739632d346562312d383937312d343731613334623234363033
    + _prefab: {fileID: 0}
    + _cachedParentPrefab: {fileID: 0}
    + _isCached: 0
    + _hasPrefab: 0
    + _parentPrefab: {fileID: 0}


    And this is the change which corrected the prefab which was always shown as missing:

    --- a/Assets/Data/GamePrefabs/Misc/LoadUIManager.prefab
    +++ b/Assets/Data/GamePrefabs/Misc/LoadUIManager.prefab
    @@ -56,7 +56,7 @@ Prefab:
    m_IsPrefabParent: 1
    --- !u!114 &114010671839222354
    MonoBehaviour:
    - m_ObjectHideFlags: 1
    + m_ObjectHideFlags: 11
    m_PrefabParentObject: {fileID: 0}
    m_PrefabInternal: {fileID: 100100000}
    m_GameObject: {fileID: 100000}
    @@ -68,21 +68,12 @@ MonoBehaviour:
    _isConnected: 1
    _guid:
    _referenceCollection:
    - _prefab: {fileID: 114010671839222354}
    _collection:
    - {fileID: 100000}
    - _hasCachedValidation: -1
    - _cachedGetIsValid: 1
    - _assetGuid: 3562343739333530613537303834366635383061393934376333306565313430
    - _cachedAsset: {fileID: 0}
    - _cachedAssetGuid:
    - _cachedObjectGuid: {fileID: 0}
    - _cachedTransform: {fileID: 0}
    - _cachedGameObject: {fileID: 0}
    - _cachedRoot: {fileID: 0}
    + _assetGuid: 5b479350a570846f580a9947c30ee140
    --- !u!114 &114792902660235394
    MonoBehaviour:
    - m_ObjectHideFlags: 1
    + m_ObjectHideFlags: 11
    m_PrefabParentObject: {fileID: 0}
    m_PrefabInternal: {fileID: 100100000}
    m_GameObject: {fileID: 100000}
    @@ -91,9 +82,4 @@ MonoBehaviour:
    m_Script: {fileID: 112998890, guid: 325c5b2a7434372429c2ca9d61dba58e, type: 3}
    m_Name:
    m_EditorClassIdentifier:
    - _guid: 62323337393639362d383739632d346562312d383937312d343731613334623234363033
    - _prefab: {fileID: 0}
    - _cachedParentPrefab: {fileID: 0}
    - _isCached: 0
    - _hasPrefab: 0
    - _parentPrefab: {fileID: 0}
    + _guid: 9ab198e5-f145-4f33-8e8a-362852c0b27f

    Looking at these two files, I have another idea about the problem. The prefab was not saved in the newest serializedVersion. Could that have caused your script to choke?
     
    laurentlavigne likes this.
  34. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @piojo9
    Thank you for sharing the details. Based on the diffs it looks like Unity itself is doing some very strange things and serializing data that it shouldn't. In the first diff, the one immediately after installing, there are some variables that shouldn't be serialized by Unity since they are private:
    + _cachedAsset: {fileID: 0}
    + _cachedAssetGuid:
    + _cachedObjectGuid: {fileID: 0}
    + _cachedTransform: {fileID: 0}
    + _cachedGameObject: {fileID: 0}
    + _cachedRoot: {fileID: 0}

    Also, the asset GUID seems completely wrong to me (3562343739333530613537303834366635383061393934376333306565313430). This GUID should be the result of AssetDatabase.AssetPathToGUID, which should return a much shorter GUID.

    After reimporting the values seem correct (second diff): the private fields are no longer serialized and the GUID value is shorter (5b479350a570846f580a9947c30ee140).

    I'll file a bug report with Unity and see if they have an explanation for this strange serialization behavior (it is definitely not the Nested Prefabs plugin that is serializing this data). Once I get an answer from Unity I'll let you know.

    If possible, can you send the complete prefab file before installing, after install and after reimporting? I am sure it would be a help for the Unity support team if they could take a look at it (although the diffs are already very useful).

    In the meantime, I recommend uninstalling Nested Prefabs as there might be unexpected results here.
     
    laurentlavigne and piojo9 like this.
  35. piojo9

    piojo9

    Joined:
    May 29, 2015
    Posts:
    10
    I've been surprised by that too, before. Unity actually does serialize private variables, and even [NonSerialized] variables. It has for years (maybe always). It just doesn't normally write them to disk. I believe this is part of the asset load/unload process that needs to happen when you start/stop the game, change scenes, or instantiate a prefab. I even had to write a DoNotSerializeMe<T> class just to hold a reference to a serializable class as a member variable, but absolutely stop Unity from trying to serialize it. (Unity isn't smart enough to try to serialize generic classes, except List<T>.)
     
    laurentlavigne likes this.
  36. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Sounds interesting, I have never experienced it myself. I have contacted Unity to see if they can clarify what is happening here. Hopefully, they will answer soon.
     
    piojo9 likes this.
  37. LuckyMDI

    LuckyMDI

    Joined:
    Jun 1, 2017
    Posts:
    11
    Great work on this plugin. I've played with the trial version a bit and it looks promising to use for my team.

    The main hurdle I've seen so far is the need to add Prefab Overrides to every instance of the nested prefab for every property change that I want saved in the parent prefab. Perhaps you've already looked into this or you're currently looking into it, but I wanted to ask...

    Are you able to make it so that when I apply changes to the currently selected prefab (whether through Unity's Apply button or one of your Apply methods in your right-click context menu for the prefab), it saves all dirty values from any child nested prefabs to the current prefab? Basically, it always saves all dirty values to the currently selected prefab as overridden values. Essentially, eliminating the step to add Prefab Overrides for every such case. If I actually wanted the value to be saved in the child nested prefab, I would instead have that child nested prefab selected when applying.
     
  38. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @eeckul
    Thanks, glad you like it.

    Automatically adding the modified values to the overrides during an apply is not possible I am afraid. First of all the plugin won't be able to know for sure where you want to save the overrides (the parent prefab? or the parent of the parent? parent of parent of parent, etc.). Secondly, there are some technical limitations which make it impossible to add them automatically.

    However, I should be able to add a list of modified properties to the "Add Override" pop up in the Prefab Overrides component, along with an "Add All Modified Properties" button to add all of them at once. Would that work for you?
     
  39. LuckyMDI

    LuckyMDI

    Joined:
    Jun 1, 2017
    Posts:
    11
    Thanks for the reply! I figured there was probably some limitation that prevented you from doing that.

    Your suggestion of an "Add All Modified Properties" button would be a great compromise. My original request is basically that, except that the button exists on the parent prefab and clicking it does the "add all modified properties" call on every nested prefab within it.

    However, if you're only able to include an "Add All Modified Properties" button on each of the nested prefabs that each need to be clicked, that's definitely a much improved workflow from the current method.

    I'm looking forward to it! And I'll definitely be purchasing the full version. :)
     
    Visual-Design-Cafe likes this.
  40. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @eeckul
    I should be able to add all nested prefabs to a single list, with a single button :) I'll post some early screenshots here once I have something working
     
  41. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    For everyone who is following this thread and has not yet decided to purchase Nested Prefabs: the asset is currently on a (secret) summer sale and is 50% off! Now is your chance to grab it for a low price here: https://goo.gl/sjWbwt :)
     
  42. v-line

    v-line

    Joined:
    Feb 13, 2013
    Posts:
    10
    Hi I have an issue. From time to time, all or some of the object become null in prefabs.

    My feeling, that it happens usually after I save the scene that contans the prefab.
     
  43. LuckyMDI

    LuckyMDI

    Joined:
    Jun 1, 2017
    Posts:
    11
    Awesome! Looking forward it! Also, just purchased it. :)
     
    Visual-Design-Cafe likes this.
  44. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25

    I also seem to have this problem. If I apply my prefab with "Apply All" or the standard apply button some of my script references are lost, I'm using unity 2017.1...

    I just bought the package and I can't use it :/
     
    Last edited: Aug 7, 2017
  45. TimNeck

    TimNeck

    Joined:
    Apr 24, 2017
    Posts:
    5
    Hi,

    I am using a custom editor script to save lightmap data so it is maintained when copying an object or instancing from a prefab. In combination with the nested prefabs this requires PrefabOverrides so your nested prefab lightmap data is not altered when applying the parent prefab. This way you can have different lightmap data on an instance of a prefab when it is nested among other objects. The problem is that the PrefabOverrides Component does not seem to update the values of it's overrides until the object is selected in the editor. So when i use my custom editor method "SaveAllLightmapData" and immediately hit apply on a prefab with nested prefabs that have PrefabOverrides, the overrides are not updated to the values I just saved and will not be applied to the prefab correctly. So my question is: Is there a way to "update" the values of PrefabOverrides from code?
     
  46. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @v-line , @ShedowH
    I am sorry to hear you are having some issues with the object references. Can you let me know what kind of object references are reset? Are these relative object references to an object inside the prefab, another object in the scene, an asset or another type of reference? If possible, can you share a screenshot of your prefab setup and the component containing the reset object reference?
     
  47. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    This is correct, the values are not updated unless selected. You can use one of the following two methods to manually update the values through code:

    1. This will set the value of a single prefab override:
    Code (CSharp):
    1.  
    2. PrefabOverride prefabOverride = PrefabOverrideUtility.GetOverrideProperty(
    3.             Selection.activeGameObject.GetComponent<PrefabOverrides>(), // Replace this with the PrefabOverrides component that stores your overrides.
    4.             Selection.activeGameObject.GetComponent<MeshRenderer>(), // Replace this with the MeshRenderer (I assume) of the target GameObject.
    5.             "YourLightmapProperty" ); // Replace the property with the target property that should be updated.
    6.  
    7.         prefabOverride.SetValue( 5f ); // Replace the value with the actual value of the property.
    8.  
    2. This can be used to update all prefab overrides at once:
    Code (CSharp):
    1. // Get the internal generic method for setting the value of a prefab override.
    2.         // Has the same effect as using PrefabOverride.SetValue but does not require any type to be given.
    3.         // It will directly copy the value from a SerializedProperty.
    4.         MethodInfo setOverrideValueGeneric = typeof( PrefabOverrideUtility ).GetMethod(
    5.             "SetOverrideValue",
    6.             BindingFlags.NonPublic | BindingFlags.Static,
    7.             null,
    8.             new System.Type[] { typeof( PrefabOverride ), typeof( SerializedProperty ) },
    9.             null );
    10.  
    11.         // Loop through all prefab overrides stored in the PrefabOverrides component.
    12.         prefabOverridesComponent.ForEachProperty(
    13.             ( Object target, PrefabOverride @override, string serializedOverridePath ) =>
    14.             {
    15.                 // Find the target SerializedProperty of the prefab override by path.
    16.                 SerializedObject serializedObject = new SerializedObject( target );
    17.                 SerializedProperty serializedProperty = serializedObject.FindProperty( @override.Path );
    18.  
    19.                 // It is possible that the SerializedProperty can not be found.
    20.                 // For example, if the target serialized property has been removed from a custom script.
    21.                 if( serializedProperty == null )
    22.                     return;
    23.  
    24.                 // Set the value of the prefab override to the value of the property.
    25.                 setOverrideValueGeneric.Invoke( null, new object[] { @override, serializedProperty } );
    26.  
    27.                 Debug.Log( "Updated prefab override value of " + @override.Path );
    28.             } );
    Edit

    Make sure to include the following:
    Code (CSharp):
    1. using System.Reflection; // Only when using method #2
    2. using VisualDesignCafe.Editor.Prefabs;
     
  48. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25


    All the values inside the circle is lost upon applying. There are transforms and gameobject references, they referencing objects in the scene.

    I currently uninstalled nested prefabs but when I had it the setup was as followed.

    Player_Apartment is the root prefab

    Computer, couch, kitchen, refrigerator, bed and boor was nested prefabs.
     
  49. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @ShedowH
    Thank you for sharing the details. If the Player_Apartment was the root prefab and the Door was a nested prefab then the "Outside Pos" and "Inside Building" are invalid references because the reference points to the parent of a nested prefab. When the nested prefab is saved as an asset, these parents do not exist (in the Door prefab asset) and therefore the references can't be found, resulting in null references. The Nested Prefabs plugin should show a warning about this in the console when applying changes.

    It is possible to save these references correctly by adding a PrefabOverrides component to the Door nested prefab and then adding prefab overrides for those two references. Since the prefab overrides are saved in the parent prefab (Player_Apartment) the references should be saved correctly as well.
     
  50. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25
    Doesn't that defeat the whole purpose of nested prefabs? To use an already configured prefab inside another?

    I dont think I'm following what you're saying hehe.

    As I understand I should not have to add prefabovverides to all my nested prefabs right?