Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Nested Prefabs: Fully integrated, Completely automatic

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

  1. LuckyMDI

    LuckyMDI

    Joined:
    Jun 1, 2017
    Posts:
    11
    @Visual-Design-Cafe

    You might already be planning to do this, but seeing the discussion above regarding prefab overrides only updating upon selection of the object, I thought I'd ask.

    Can you make the upcoming shortcut button for adding all overrides also update the values of existing overrides?
     
  2. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Absolutely not :) Only these two object references have to be overridden. I'll try to explain the situation with the attached example image:
    support_nested_prefab_reference_to_parent.jpg
    In this case, the "Player_Apartment/Door" prefab contains an object reference to the "Player_Apartment/Interiors" object, the "Player_Apartment/Interiors" object is a parent of "Player_Apartment/Door". When the "Player_Apartment" prefab is saved (left side in the screenshot) these object references are saved correctly.

    However, because "Player_Apartment/Door" is a nested prefab, the data of that prefab, including the object references, is saved in the "Door" prefab. When saving the "Door" prefab the "Player_Apartment/Interiors" object does not exist, only the "Door" prefab exists (right side in the screenshot"). Therefore the object references cannot be found and are null.

    Because the nested prefab "Player_Apartment/Door" is linked to the original "Door" prefab, these null references are loaded from the "Door" prefab asset and the references in the "Player_Apartment/Door" prefab are set to null as well.

    To fix this, you can add a Prefab Override in "Player_Apartment/Door" for the object references. This will save the values of the object references inside the "Player_Apartment" prefab, instead of the "Door" prefab. Only object references that refer to a parent of a nested prefab have to be overridden, all other references will work normally.
     
  3. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Yes, that should be possible. I'll take another look at the whole updating process and see if the overrides can be refreshed in a better way as well.
     
    LuckyMDI likes this.
  4. NikMikk

    NikMikk

    Joined:
    Nov 4, 2015
    Posts:
    25

    I see, thanks for explaining, will look into it!
     
    Visual-Design-Cafe likes this.
  5. juanelo

    juanelo

    Joined:
    Jan 28, 2011
    Posts:
    46
    Hi, Visual-Design-Cafe. The asset looks great. I was wondering if you had considered any sort of porting from Prefab Evolution to 'Nested Prefabs', or if you had any suggestion as to how to go about converting a project that used Prefab Evolution to your system. Thanks!
     
  6. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @juanelo
    Thanks, glad you like it. Unfortunately, there is no way to automatically convert a Prefab Evolution project at the moment. I am afraid you will have to manually rebuild all nested prefabs. I'll put it on my schedule to do some research about Prefab Evolution to see if an automatic solution can be made for this, but it will be at least a couple of weeks (2 or 3) until I will be able to make one.
     
  7. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    I have been working on making adding prefab overrides easier. It is now possible to select one or more (or all) properties from a list of modified properties. Does anyone have any feedback? :)

    @eeckul Do you think this will work for you?

    prefab_overrides_modified_properties_2.gif
     
  8. LuckyMDI

    LuckyMDI

    Joined:
    Jun 1, 2017
    Posts:
    11
    That looks great. I think that will work well for us. Thank you!

    I can give more feedback once I've had time to try it out.
     
    Visual-Design-Cafe likes this.
  9. v-line

    v-line

    Joined:
    Feb 13, 2013
    Posts:
    10
    I didn't notice that the forum was updated.

    I did a bit more research on the issue. Seeme that when you update the prefab, and you have just added a refereence to one of the child objects (or to the object itself) there is a chance for the references to be null. If you try to add the references again, and update the prefab again, usually it works fine.

    Also seeme that the references just disapear from time to time. Here I have not foud any correlation with my actions.

    I tried to reproduce it in a small project with one test script and could not. But it happens in my big project. So I wonder if there could be a conflict with some other assets/version control tool (Plastic SCM).

    The screenshot (just an example, as I told I was nto able to reproduct the issue in a small test project):
    before apply.PNG
     
  10. v-line

    v-line

    Joined:
    Feb 13, 2013
    Posts:
    10
    I have just posted the comment, and then I noticed this one. For me it happens even with flat prefabs, that doesn't include any other prefabs. And when I edit it, I just drag and drop the prefab to a scene, so it is not a part of a bigger prefab and doesn't have any references to anything outside the prefab.
     
  11. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @v-line
    Thank you for sharing additional information about the issue you are having. The situation you describe should work in a normal test situation, which is probably why you can't reproduce it in a test project. We have an automated unit test specifically for this situation to make sure new object references in new scripts to new children are saved correctly.

    The most likely cause here is that one of the children is not registered internally. If a child is not registered it will be replaced during the next apply. You won't be able to see this because the replaced object will be exactly the same (same components and properties). But it will have a different ID. Because of the different ID, the object reference to that object will be lost, as references are matched by ID. You can see if this issue happens in your project by looking at the prefab icons in the hierarchy. If one of the icons has a yellow question mark on it then it is missing a child internally.

    There are a few ways to fix this when you spot a question mark (also see the documentation):
    1. Right-click on the prefab icon and choose “Fix”
    2. Revert the changes to the prefab through the Revert button in the Inspector
    3. Apply the changes to the prefab through the Apply button in the Inspector
    4. Reimport the prefab
    One of the main causes for these missing children is merging issues with version control. Please make sure your asset serialization mode is set to "Force Text". This way the prefab files will be saved as text and can be merged correctly by version control.

    If this problem keeps happening then, if possible, please give me access to your project so I can debug it. If you can't give me access then I'll do what I can to help you remotely.
     
  12. v-line

    v-line

    Joined:
    Feb 13, 2013
    Posts:
    10
    Thanks for your help. I have not noticed any yellow question marks in in the hierarchy. I will try to switch the serialization to the Forced Text mode. And I will update you if the problem will occur again.
     
    Visual-Design-Cafe likes this.
  13. tropezon

    tropezon

    Joined:
    Aug 8, 2017
    Posts:
    4
    I have a really itchy situation.
    In Object A have class A, and in prefab B have class B.
    Class A have the reference for class B passed in editor.
    On Start class A i subscribe one method to event in class B.
    When event is fired, i don't see calls to subscribed methods of class A. Checked id references of class b and see that when i subscribe to event, reference to class B change in exectution time, loosing all the references to subscribed events.
    Is this a bug of nested Prefabs?
     
  14. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @tropezon
    The situation you describe should work just fine. I have double checked it and I can't seem to find any problem with it. I have used the following setup:
    nested_prefab_event_reference.jpg

    I have tried to set an event directly with System.Action and the Unity event sytsem. Besides that, I also created a persistent event in the inspector. All of them seem to work fine. There is one thing you should note here and that is that the persistent event requires a Prefab Override for the object reference. This is because Object A is a parent of Prefab B and it is not possible to set a reference to a parent prefab directly.

    If you have a similar setup but it doesn't work for you then can you share a screenshot of your prefabs and code? Nested Prefabs is completely disabled at runtime, so it is unlikely that it is a bug, but there might be a small mistake in your setup. I'll gladly help you out if you can send more details.
     
  15. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Version 1.2.4 of Nested Prefabs is now available for download. You can download it through the Asset Store or with the built-in downloader, which should open automatically.

    Unity 2017 made some internal changes which might prevent the downloader from working. If you see any exceptions when the download window opens, then please download from the Asset Store instead.

    The main changes in this version are:
    - Apply times should be lower due to performance improvements and because of removing legacy code.
    - Prefab Overrides can now be added from a list of modified properties.

    For a full list of changes please visit the online changelog.

    @eeckul
    The list of modified properties has been added to the Add Override pop-up in this version. Please let me know if you have any feedback :)
     
    tapawafo likes this.
  16. DanielGravient

    DanielGravient

    Joined:
    May 26, 2017
    Posts:
    2
    Visual-Design-Cafe

    One question. We have purchased this plugin with my team and we have a problemon with Subversion.

    We have a prefab inside a prefab. And when we make a change on the inside prefab, subversion detects changes on both. We thought that container prefab wiuld have reference to the other prefab but maybe it isn't like that.

    Thanks for your help.
     
  17. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @DanielGravient
    The container (root) prefab stores a reference for the nested prefab, as well as its data. When you make a change both the original prefab and the nested prefab are modified, so this is expected behavior. This is necessary because Unity does not support nested prefabs natively and storing and modifying the data on both prefabs is the only workaround. Therefore I am afraid there is nothing that can be done about this. Hopefully, it is not too much of an inconvenience for you.
     
  18. RyanNguyen

    RyanNguyen

    Joined:
    Jul 20, 2016
    Posts:
    8
    Hi Visual-Design-Cafe!
    I just bought the Assets 2 weeks ago (If you need to see the invoice please contact me)
    After applying research to my project, I have one problem with Nested Prefabs
    I've Prefab A, B and C. I add two Prefabs A and B to Prefabs C
    It will look like this:
    C
    |__A
    |__B

    I add a script into A to save a references of prefabs B to a public GameObject variable
    Code (CSharp):
    1. public GameObject saveB;
    I understand that although A and B are prefabs and I can not save the references from them, but its still a children of C, does Nested Prefabs have any solution for this problem?
    Thanks.
     
  19. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @RyanNguyen
    Thank you for using Nested Prefabs. If I understand correctly you want to save a reference from prefab A to prefab B. You can do this by adding a prefab override for the "saveB" property.

    You should add a "Prefab Overrides" component to the prefab A that is inside prefab C. Then click "Add Override" and choose the "saveB" property. Overridden properties are saved in "Prefab C" so the reference should be saved correctly.
     
  20. lightmont

    lightmont

    Joined:
    Oct 8, 2016
    Posts:
    13
    Hello @Visual-Design-Cafe
    We found out about Nested Prefabs just days ago and we immediately bought it. We used Prefab Evolution for our projects, but it is immensely slow on big projects. We can save time using nested prefabs, but the time lost overall is bigger.

    We understand you made a great work to create the asset, and it works really well when you need nested prefabs which are somehow "static", meaning you just put prefabs inside other prefabs and you don't need dynamic overrides.

    Our needs are strongly related to the override part of working with nested prefabs.

    Example: we may create different Button Models, each of which have mandatory fields that must be set (override, in your terminology) when an instance of the model is created, example of models:

    1. Button Model 1: Squared, Green
    2. Button Model 2: Circular, Blue
    3. Button Model 3: Rectangular, White

    We need to put those models in the scene and set a *different* icon for each instance—an override basically.

    Then, if we need to change something in the structure of the model, example: adding a script or making all the green buttons to be yellow, we just make the change to the model and then it must propagate to each "children" prefabs.
    So we save the time to search for all the "Squared, Green" buttons in the scene and make the changes to each of them manually.


    We made some tests on the asset "Nested Prefabs", and we discovered these facts:

    • If we create an instance of a model, i.e. adding the model into the scene, and set the override for an icon, we **cannot** make that instance a prefab. Hence, we cannot instantiate it if we need to.
    • Perhaps it was our inexperience with the asset, but it was really easy to press the wrong apply and push unwanted changes to all the prefabs nested.
    • It is not possible to create "models" of prefabs with mandatory overrides.



    Another example, which was our heavy usage of Prefab Evolution, is:

    • Create a structure/model for a character, which will then be used to create "children" characters, each of which have different sprites, or some public parameter in its scripts set to different values.
    • Each children must be made as a prefab, because it must be instantiated during the game, depending on what the player chooses to play with.
    The problem with the asset "Nested Prefabs" is that we can make overrides, but we cannot make prefabs out of those instances that contains overrides.
    If we create the model for the characters, and then we need to make a change (adding a script for instance) to the model, we need that this change must be automatically propagated to all its children.

    This seems only accomplishable with "Nested Prefabs" if all the children are always present in the scene.
    Also, when we need to create a new actual character, we need to re-add the overrides each time, which is a quite time-expensive and an error-prone operation.



    Will it be possible to address those issues in future updates?

    Thank you.
     
  21. RyanNguyen

    RyanNguyen

    Joined:
    Jul 20, 2016
    Posts:
    8
    Thanks Visual-Design-Cafe for your support!

    Does Prefab Overrides support for PlayMaker variables?
    After using Nested Prefab, if I log in and use Unity Collaborate, my project is getting heavier and Unity Editor is really slow and sometime it's lag. I was fix this by log out from Unity Collaborate

    We look forward to the updates in the future.
    Thanks.
     
    Last edited: Sep 9, 2017
  22. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @lightmont
    Thank you for purchasing Nested Prefabs. I looked into the scenarios you described and most of them should be possible with Nested Prefabs.

    It is possible to save the instance, including overrides, as a new prefab. However, you have to add a new parent for the prefab to make sure it is nested and not the root object. If you look at the following screenshot you can see that there is a generic button prefab ("Button") and three variations of that button ("Squared Green, Circular Blue, and Rectangular White"). The variations each have their own root objects, with the "Button" as a child. The "Button" then has a Prefab Overrides component to override the Color and Sprite property, so each button variation can have a different color and image.

    save_instance_with_overrides_as_prefab.jpg

    I recommend adding a prefab override (through the Prefab Overrides component) for each property that you do not want to apply. Besides that, I recommend taking a look at the documentation page to make sure you understand the different apply buttons.

    There is indeed no way to create a model with mandatory overrides. However, you can very easily save an existing prefab as a new asset. For example, if you need another variation for the button then you can save the "Circular Blue Button" as a new prefab and it will include all the overridden properties.

    Please see the above answer for this. It is indeed not possible to specifically create a structure/model/template/blueprint. However, you can make a prefab structure with all the properties that should be overridden and simply duplicate it.

    If you add a new parent as in the screenshot above then all of this is possible without any problem. And as mentioned before you can duplicate existing prefabs, including all overridden properties, so you don't have to re-add them.

    Hopefully, this information will help you out. Please feel free to reach out if you any further questions.
     
  23. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    It has not been specifically tested with PlayMaker so I am not sure, to be honest. Prefab Overrides is supported for every property that can be serialized by Unity, but I do not know how PlayMaker saves its variables. I do not use or own PlayMaker myself so I won't be able to test it out at the moment. My apologies for not being able to give you more information regarding PlayMaker.

    Regarding Unity Collaborate: this is most likely an issue with Collaborate itself and not with Nested Prefabs. Other users use Nested Prefabs and Collaborate as well and I have never received any report of issues. However, Collaborate itself is still in quite early development and has several problems with performance and editor freezes. I recommend contacting Unity about Collaborate if you continue experiencing problems.
     
  24. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    I'm using the trail version of your tool and have some notes/questions:

    1. The Right click menu doesn't have the various Apply prefab and Fix options that are mentioned in the documentation
    2. There is a option in Window > Visual Design Cafe > Nested Prefabs > "Build Example" - what does this do?
    3. When a nested prefab is selected, the Select button in the inspector doesn't select the appropriate child prefab, but instead its position in the root prefab. I usually use this to navigate to the correct prefab for finding it in the project.
    Otherwise the tool is looking good, cheers.
     
  25. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Thank you for trying out Nested Prefabs.

    1. You might be right-clicking on a model prefab, which has a slightly different menu. Because nested model prefabs can't be edited directly they do not have an "Apply Prefab" or an "Apply Prefab and Children" button (see screenshot).
    The "Revert to Model" button here reverts the nested model back to the original model. "Revert to Prefab" only reverts modifications that are not yet applied.

    On the left side is the context menu for nested prefabs, on the right side the one for nested models.
    context_menu_items.jpg

    2. It is an example of how to use the Nested Prefabs API to make a build if you are using a custom build pipeline. Please take a look at the documentation page about building for more information (the last item on the page is about this). You can delete the "CustomBuildPipeline" script if you don't need it and don't want the additional item in your menu.

    3. That is correct. Since those buttons are native Unity buttons I can't modify their behavior at the moment. If you want to navigate to the correct prefab you can click on the prefab icon in the hierarchy once and it will ping the original prefab.

    Hopefully, this will help you out. Feel free to reach out if you have any further questions.
     
  26. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    Cheers, I didn't realize the coloured prefab icon on the left of the name in the hierarchy was clickable, that solves the finding prefab button, and the right click context menu thing.
     
    Visual-Design-Cafe likes this.
  27. DanielGravient

    DanielGravient

    Joined:
    May 26, 2017
    Posts:
    2
    Unfortunately the plugin is not useful for us because of that. Hope Unity integrate a real solution for that soon.
    Thanks for your support.
     
  28. omar_duarte

    omar_duarte

    Joined:
    Sep 12, 2017
    Posts:
    1
    I recently purchased your plugin, but when I run the game (in the Editor so far) it randomly throws this exception:

    NullReferenceException: Object reference not set to an instance of an object
    VisualDesignCafe.Editor.Analytics.GoogleAnalyticsMPV3+<HandleWWW>d__21.MoveNext ()
    UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)

    Thanks for your support.
     
  29. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @omar_duarte
    Thank you for reporting this error, I have never seen it before. I made a change that will hopefully fix this error, I'll send you a custom build by PM.
     
  30. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    I'm concerned this may be a problem for us, I wonder what happens when there are conflicting changes and how, if at all, they could be merged.
    FYI we use Perforce
     
  31. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    I have received an answer from Unity regarding the bug report I sent with the serialization issues you had. Unfortunately, Unity is not able to reproduce this as well:
    If you have this issue again then I recommend to contact Unity directly and send them your project so they might be able to debug it. I am afraid I won't be able to fix it for you.
     
  32. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    @jschroyen
    If there are conflicting changes, for example, the original prefab has a property value that was changed from 1 to 5 and the same prefab, but nested in a different prefab, has the value changed from 1 to 3. Then the value of the prefab that was last imported will be applied to the other nested prefabs/original prefab. If the prefab containing a nested prefab was last imported then all values will be changed to 3. If the original prefab was last imported then all values will be changed to 5. You will not have any conflicts in version control.

    If a prefab containing the nested prefab was last imported and all values are changed to 3, then the original prefab will be marked as modified in version control and you can see that the value changed from 5 to 3. If you wanted the value to be 5 and not 3, then you can revert the original prefab and the prefab and all nested prefabs will be changed to have a value of 5 instead.
     
  33. jschroyen

    jschroyen

    Joined:
    Aug 19, 2015
    Posts:
    22
    Thanks for the clarification. If we're careful we should be able to diff and find the intent if there is a collision.
    Talking about nested prefabs is always a headache ;)
     
  34. lightmont

    lightmont

    Joined:
    Oct 8, 2016
    Posts:
    13
    @visua

    @Visual-Design-Cafe

    Thank you for your in-depth response. We will implement the techniques you describe and see if it fits our needs.

    Perhaps, our initial impact with using Nested Prefabs has been highly skewed by the approach we were used to adopt with Prefab Evolution, which is quite different.
    We will need to adapt to the Nested Prefab approach.

    Thanks!
     
  35. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    186
    @Visual-Design-Cafe

    Hey, developer of Odin Inspector & Serializer here. We recently had a bug report regarding an interaction Odin seems to have with this asset, and it seems to be one that we can't really do anything about on our end without ugly hacks, so hopefully you can fix it on your end :)

    It seems that when both Odin and this asset are installed in the same project, the following exception is logged every time scripts reload:

    Code (csharp):
    1. System.NullReferenceException: Object reference not set to an instance of an object
    2.   at VisualDesignCafe.Editor.Prefabs.Guid.GetHashCode () [0x00000] in <filename unknown>:0
    3.   at Sirenix.Utilities.ReferenceEqualityComparer`1[UnityEngine.Object].GetHashCode (UnityEngine.Object obj) [0x00000] in C:\Sirenix\Sirenix Solution\Sirenix.Utilities\Misc\ReferenceEqualityComparer.cs:34
    4.   at System.Collections.Generic.HashSet`1[UnityEngine.Object].GetItemHashCode (UnityEngine.Object item) [0x00000] in <filename unknown>:0
    5.   at System.Collections.Generic.HashSet`1[UnityEngine.Object].Add (UnityEngine.Object item) [0x00000] in <filename unknown>:0
    6.   at Sirenix.Serialization.UnitySerializationUtility+PrefabSelectionTracker.RegisterRecursive (UnityEngine.GameObject go) [0x00017] in C:\Sirenix\Sirenix Solution\Sirenix.Serialization\Utilities\UnitySerializationUtility.cs:1887
    7.   at Sirenix.Serialization.UnitySerializationUtility+PrefabSelectionTracker.OnSelectionChanged () [0x0006d] in C:\Sirenix\Sirenix Solution\Sirenix.Serialization\Utilities\UnitySerializationUtility.cs:1862
    8.   at Sirenix.Serialization.UnitySerializationUtility+PrefabSelectionTracker..cctor () [0x0002f] in C:\Sirenix\Sirenix Solution\Sirenix.Serialization\Utilities\UnitySerializationUtility.cs:1839
    9. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()
    As you can see, in InitializeOnLoad, Odin initializes a selection tracker that keeps track of all currently selected prefab components in a HashSet. What seems to be happening is, it detects one of your prefabs, and then when that prefab is added to the hashset, GetHashCode() is called on it via our ReferenceEqualityComparer, and something about its internal state causes a null reference exception to be thrown.

    InitializeOnLoad, it should be noted, is invoked before the prefabs have been deserialized, so likely the values in the prefab haven't been initialized yet. Generally it's a good rule of thumb that GetHashCode should be safe to call even on non-initialized class instances, so my suggested fix would be to incorporate null checks into that GetHashCode implementation, or have a special "uninitialized" hashcode value that you return when the object hasn't been deserialized yet.

    For reference, the code of our ReferenceEqualityComparer is as follows:

    Code (csharp):
    1. namespace Sirenix.Utilities
    2. {
    3.     using System.Collections.Generic;
    4.  
    5.     /// <summary>
    6.     /// Compares objects by reference only, ignoring equality operators completely. This is used by the property tree reference dictionaries to keep track of references.
    7.     /// </summary>
    8.     public class ReferenceEqualityComparer<T> : IEqualityComparer<T> where T : class
    9.     {
    10.         /// <summary>
    11.         /// A default, cached instance of this generic variant of the reference equality comparer.
    12.         /// </summary>
    13.         public static readonly ReferenceEqualityComparer<T> Default = new ReferenceEqualityComparer<T>();
    14.  
    15.         /// <summary>
    16.         /// Returns true if the object references are equal.
    17.         /// </summary>
    18.         public bool Equals(T x, T y)
    19.         {
    20.             return object.ReferenceEquals(x, y);
    21.         }
    22.  
    23.         /// <summary>
    24.         /// Returns the result of the object's own GetHashCode method.
    25.         /// </summary>
    26.         public int GetHashCode(T obj)
    27.         {
    28.             return obj.GetHashCode();
    29.         }
    30.     }
    31. }
    Cheers!
     
    Last edited: Sep 22, 2017
  36. Deusald

    Deusald

    Joined:
    Feb 11, 2014
    Posts:
    31
    This System.NullReferenceException occurs even when selecting objects in hierarchy.
     
  37. lightmont

    lightmont

    Joined:
    Oct 8, 2016
    Posts:
    13
    Confirming this issue. It happens to our projects too.
     
  38. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Thank you for notifying me about this issue. I have looked into it and there was indeed an issue where the value of the prefab was not yet initialized when Odin calls GetHashCode(). It has been fixed now and a new build is ready.

    It can take some time until this new build is available on the Asset Store as there are a few other updates that have to be released as well. Can you please ask the user that sent the bug report to send an email to support@visualdesigncafe.com? Then I'll make sure to send a custom build with a fix directly.

    I see some posts above here regarding the same issue (@Deusald and @lightmont). I'll send you a PM with a custom build that should fix this issue.
    Edit: @Deusald. It seems I can't send you a PM. Can you send an email to support@visualdesigncafe.com as well? Then I'll send you a build with a fix for the problem.

    @Tor-Vestergaard
    After testing out the demo that came with Odin I also noticed another thing that didn't work very nicely together, though it didn't cause any problematic errors so far. If you open the demo scene that comes with Odin and create a nested prefab out of the Serialize Anything object then Nested Prefabs will show the following warning:
    This warning means that the 'serializationData.Prefab' property holds a reference to the prefab asset. Unity can't handle these kinds of references properly because it will get confused between the reference to the asset and relative references within the prefab. When loading the serialized data of a Nested Prefab it is not possible to differentiate between the asset reference and a relative reference and the reference can't be loaded correctly. Therefore, these kinds of references are not allowed in nested prefabs. The Nested Prefabs plugin will clear this reference when applying changes to the prefab.

    So far it doesn't seem like it causes any problems with Odin or Nested Prefabs, but I would like to ask you if you can give me some more information about what this property does and why it stores a reference to a prefab. Then I can check if an exception for this property can be made or if it can be ignored completely by the Nested Prefabs plugin so we can get rid of the warning.
     
    Last edited: Sep 25, 2017
  39. Tor-Vestergaard

    Tor-Vestergaard

    Joined:
    Mar 20, 2013
    Posts:
    186
    Thank you, that's excellent news. I've sent an email to the person in question.

    Odin comes with its own custom prefab modifications system bolted on top of Unity's modification system (to support modifications to Odin-serialized data such as dictionaries, polymorphic types, etc), and it needs a reference to the prefab asset of the prefab instance (we prefer to deserialize Odin data directly from the prefab asset and then apply modifications over it). We have fallbacks in case the reference breaks for some reason, but not having said reference does make the system more fragile, so it would be best if it is left alone.

    You're entirely correct that Unity doesn't usually know how to handle this sort of reference, but we set it (and all of the data for our own custom modifications, in the form of serialized json strings) manually using PrefabUtility.SetPropertyModifications, and in this case it works just fine, since it is never exposed in the inspector for Unity to mess up. At least, we have not had any issues with it so far.

    Of course, we are very careful when setting the modifications manually, and we don't touch any pre-existing modifications that are not part of the serializationData struct, so if you mess with the modifications yourself, that should still work fine as long as Odin's are left alone. I'm not sure how our custom modifications interact with your nested prefabs, though - it seems very possible that there will be some issues there.
     
    Last edited: Sep 25, 2017
  40. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Thank you for the information. We should be able to add an exception for the property and ignore it for nested prefabs. I'll make sure to include it in the next release. If you ever run into stability issues because of this reference (with Unity in general, not necessarily with Nested Prefabs) then I recommend storing the asset GUID of the prefab asset as a string instead of a direct reference.

    Regarding setting the modifications of a prefab. Nested Prefabs mostly runs as an asset postprocessor and only modifies the prefab assets. As long as Odin serializes and deserializes all data before the asset postprocessor runs (looks like it does) then there shouldn't necessarily be any compatibility issues. Nested Prefabs is also very careful not to modify any data that it shouldn't and to support custom serialization.

    Though, if you do notice something that doesn't work nicely together then please contact me here, through PM or by email and I'll see what I can do to integrate both assets in a better way. If you want to check things for yourself then let me know and I'll send you the latest release build of Nested Prefabs so you can give it a try.
     
    Tor-Vestergaard likes this.
  41. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Hey,

    I managed to break your plugin within a few hours. =)

    Code (CSharp):
    1. Nested Prefabs: Unhandled exception (details below). Please report this as a bug to the developer (support@visualdesigncafe.com) if this exception keeps appearing.
    2. Bug report:
    3. {
    4.     Message: "Object reference not set to an instance of an object (NullReferenceException)"
    5.     Version: "1.2.4.36"
    6.     StackTrace: "  at VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor.OnPostprocessPrefab (UnityEngine.GameObject prefab, System.Collections.Generic.List`1 assetGuids) [0x00000] in <filename unknown>:0
    7.  at VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) [0x00000] in <filename unknown>:0 "
    8. }
    9.  
    10. UnityEngine.Debug:LogError(Object)
    11. VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:OnPostprocessAllAssets(String[], String[], String[], String[])
    12. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
    13.  
    This error happens when trying to nest any prefab now. I believe it happened after I moved a file outside of Unity.
    Existing nested prefabs from before the error are now also broken.

    I assume maybe the database got corrupted? (I saw the plugin touched every single prefab file, which si quite scary tbh... )

    Any way to fix this bug or completely reindex the nested prefabs?

    I'm quite fearful that even if I get this worked out, this might continue to happen and potentially cost me a LOT of time (and nerves haha).

    Further notes:
    - Everything works as expected in a blank project
    - I already wiped the "Library" folder and the "Cache"
    - The little "nesting icons" (the blue, purple, etc..) in the Hierarchy view are also gone if that matters

    Edit 1:
    - I tried to run a preprocess+postprocess cycle for good measure/luck and now I'm stuck with a "Build Mode" and the postprocessing fails with:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor.ClearCachedPrefabDatabase ()
    3. VisualDesignCafe.Editor.Prefabs.Database.BuildPostprocessor.OnPostprocessBuild ()
    4. VisualDesignCafe.Editor.Prefabs.Database.PrefabDatabaseUtility.PostprocessBuild ()
    5. VisualDesignCafe.Editor.Prefabs.Database.PrefabDatabaseMenu.PostprocessBuild ()
    Edit 2:
    - I tried removing and re-adding the plugin (with an intermediate "Library" purge), and the errors are "somewhat better". Nesting is still pretty much broken... trying to nest anything in the scene results in a green parent prefab with a question mark in it. =(

    Edit 3:
    Nothing here: https://www.visualdesigncafe.com/nestedprefabs/documentation/icons/ seems to be working:
    Code (CSharp):
    1. Could not fix corrupt prefab. Please check the prefab hierarchy if there are any missing or corrupt nested prefabs and remove them.

    Thanks,
    Nico
     
    Last edited: Sep 28, 2017
  42. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    I am sorry to hear you are experiencing all these errors. I have sent you an email with additional information and data so these issues can, hopefully, be fixed as soon as possible.
     
  43. nicolasgramlich

    nicolasgramlich

    Joined:
    Sep 21, 2017
    Posts:
    231
    Max supplied a new version 1.2.5.42, which fixed the issue for me after hitting "Apply" now =)
     
    Visual-Design-Cafe likes this.
  44. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Version 1.2.5 has now been submitted to the Asset Store and should be available to everyone in a couple of days.
    This new version has improved compatibility with Odin Inspector & Serializer and general fixes to improve stability and performance.
     
    Tor-Vestergaard likes this.
  45. Deleted User

    Deleted User

    Guest

    I bought this a few days ago. When there's a component that cannot find a missing script in a prefab, prefab instances of that prefab show a red X next to the prefab icon (Disconnected Prefab Instance).

    Although the "missing script" (aka. null components) are rare and most likely a mistake by the dev, it should not affect the functionality of Nested Prefabs. The best course of action would be if Nested Prefabs worked as intended, but a warning could appear that there's a problem with the prefab.

    Will you please consider fixing this?
     
  46. notagame

    notagame

    Joined:
    Sep 17, 2017
    Posts:
    17
    Hi,

    I am using prefabs to produce re-usable components (haw haw).
    One of the main requirements is that you can add a stub component on the root level of a prefab that allows instances of that prefab to affect it in well defined ways. So basically this component will "save" the instance specific customization of the prefab and I can then modify the prefab and refactor its internals without breaking any instances, as long as the prefab uses its own public interface to interact with clients...

    Now the problem is that if I modify an instance in the scene and want to propagate a change to all instances via "Apply All", it will make all the settings of the selected instance default values in the prefab. This means when I changed the prefab next time, all members that are default will be modified in instances... This sucks.

    Is there a way to declare a whole component as "instance only"? So basically whenever I hit "Apply All" this special component shall NOT be transferred into the prefab, only the existence of the component, but no specific member values...

    This way I could freely update any instance of a prefab and merge the result back into the prefab without having to worry about unwanted cascading changes because my public API component will never be updated from the prefab.

    In short, what I want is a way to mark a MonoBehaviour as "never sync from prefab", so that all its values are always instance specific and new instances of a prefab will always only create this behavior, but not initialize any values... And "Apply All" will never transfer any values to the prefab and never update the values in any instances.

    This would be immensely helpful, since otherwise the only real way to edit a prefab is by pulling a fresh instance into the scene, editing it and saving it. But that is incredibly tedious because I will usually need to integrate the instance into the scene before I can make the quick change...

    Even with pulling it into a scene you still have the problem that any default value in any instance will be affected by the changes you make. But this might not be what you want...

    I really don't know how Unity can make such a fundamental building block into such a clusterfuck. Your asset is immensely helpful, and if you can fix this issue I will be really happy with it. But that doesn't change the fact that Unity itself should have all of this pretty much from day one... Its ridiculous.
     
  47. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    Thank you for purchasing Nested Prefabs. Unfortunately, this issue is caused by Unity itself, the Nested Prefabs plugin handles missing scripts without any problem. Therefore I am not able to fix this myself. I have filed a bug report with Unity so, hopefully, they will fix it soon.
     
  48. Visual-Design-Cafe

    Visual-Design-Cafe

    Joined:
    May 23, 2015
    Posts:
    721
    You can add a VisualDesignCafe.Editor.Prefabs.DontSaveInPrefab attribute to your class, this will make sure the component is ignored when applying changes to a nested prefab. Please note that this only works for nested prefabs. Root prefabs are handled by Unity, so they will still be applied. Instances of the same prefab will also still have the applied values because they are handled by Unity as well, and unfortunately, I can't disable Unity's prefab system.

    The only way to have unique values for every single prefab instance in Unity is to override the value in the Inspector (so they are in a bold font) and never apply these changes...

    If the attribute works well enough for your case then please let me know and I can give you a custom script as well that does copy the component existence but ignores the property values. (it requires a custom postprocessor)
     
  49. tomdrin88

    tomdrin88

    Joined:
    Oct 15, 2015
    Posts:
    2
    Hi,
    we are experimenting with Nested Prefabs on our mid-size mobile game.
    First of all I find nested prefab quite pleasant to use. However we are experiancing heavy performance issues in editor.
    Especially when saving scene for first time after Unity is restarted.

    I would understand this delay when apply is hit on some nested prefab (due to caching asset db) but not when saving unrelated change in scene.

    This delay is not experienced for the second+ time the scene is saved.

    This is very annoying and makes nested prefabs not usable in our workflow.

    Is there some reason for this behaviour?
     
  50. notagame

    notagame

    Joined:
    Sep 17, 2017
    Posts:
    17
    Thanks for your response. It does not work in my case though :(. Changes are stilled applied to the prefab and all instances.

    Anyway. I figured out a solution which is a script that provides storage in the parent. So my API scripts can simply look for or create a storage script in the parent and store the data there... It's not optimal but it will work fine and is logically what this operation comes down to anyway. The settings should be owned by the parent. It is just not very clean to actually store them there directly. It would be better if there was an attribute that would provide equal behavior in the background.