Nested Prefabs: Fully integrated, Completely automatic

I’ve been using Nested Prefabs for a few days now and it’s great! Very easy to work with.

However, I’m having a strange issue.

I have a player root prefab, and in that prefab I have some nested prefabs for the head, torso, and limbs. I created these prefabs one at a time, applying to the prefab as per usual, and have had no issues until today.

When I made a change to the ‘M8HeadObj’ prefab, and also added a mesh object (‘head’ in the picture’), I can now no longer apply changes to any of the prefabs - they all display a red X and I get no errors or feedback in console.

Image: (snipped because issue was solved below)

When I right click > apply on the root prefab, nothing appears to happen. When I right click on the red-x nested prefabs, the only option is to break prefab connection.

Is this behavior familiar to you? If so, how should I resolve it?

Thanks.

@tapawafo
The red x means the (root) prefab is disconnected by Unity. The Nested Prefabs extension will prevent you from editing disconnected prefabs (locally, through the icon menu) to make sure the prefab does not get corrupted (Unity doesn’t handle changes to a disconnected prefab well). The easiest way to fix this is by clicking the Apply button in the Inspector to apply all changes and reconnect the prefab, or by clicking Revert in the Inspector.

Note: If you are using Unity 5.6 and Unity gives an error message when applying/reverting or Unity disconnects the prefab immediately then please check if there are any missing scripts on your prefab. There is a bug in Unity 5.6 that messes up the prefabs internally when there is a missing script (it has nothing to do with the extension).

@Visual-Design-Cafe
Thanks for the quick response!

I am on 5.6.0f3 and it was in fact a rogue missing script on an object deep in the hierarchy. Everything’s working. Thanks! :slight_smile:

1 Like

Hello again,

Is there any special procedure to follow when updating NestedPrefabs (the asset) to a new version? Is it the standard procedure of deleting the old version and installing the new?

I ask because I know NestedPrefabs must be installed after importing it into the project, so I want to make sure I don’t screw everything up. :slight_smile:

Thanks.

@tapawafo It is best to simply import the new package while the old version is still in the project. Unity should automatically overwrite the old plugin with the new file. It only has to be installed the first time you use the plugin in a project.

1 Like

@Visual-Design-Cafe ,

Hi - thinking about buying this when in sale. Will it work and play well with Playmaker (thinking of FSMs within child prefabs etc)?

@Duffer123_1 ,
Nested Prefabs supports all kinds of custom serialized classes and types so it should work fine with Playmaker, although it has not been specifically tested with it. If you want to be sure you can test it with the trial version: https://www.visualdesigncafe.com/products/nestedprefabs/trial/
Please let me know if the trial does not work well with Playmaker and I’ll make sure to add support for Playmaker specifically.

Hello,

I am constantly getting strange errors when playtesting a scene with a few nested prefabs in editor. The errors do not seem to occur on a fresh restart of Unity, or at least without messing with any objects in the scene before hitting play.

The errors during play mode seemed at first to occur randomly, but I think they’re happening any time anything in a prefab in the scene is changed.

The errors occur in pairs, first,

Failed to create Nested Prefab
(pastebin of full log Failed to create Nested Prefab0x000000014179D92B (Unity) StackWalker::GetCur - Pastebin.com )

and then,

Assertion failed on expression: ‘!m_isUndoing’
(pastebin of full log Assertion failed on expression: '!m_IsUndoing'0x000000014179D92B (Unity) Stack - Pastebin.com )

When I said above that the errors occur when something is changed, I mean if it’s done via script, or even if I change a value while in playmode - it undoes the value I changed, and throws that error.

Thanks in advance for any help.

@tapawafo

I have looked into the issue and there is still a postprocessor running during playmode, which shouldn’t happen. The postprocessor checks the nested prefabs in the scene if they are valid and detects changes. In playmode all nested prefabs are removed/disabled so it runs into an error since it can’t find the prefab. I have fixed it and will publish an update as soon as possible.
My apologies for the inconvenience this is causing.

1 Like

@Visual-Design-Cafe

Fantastic! I was worried it would be something more serious. Glad to hear you found the solution. :slight_smile:

Thanks.

Important notice for everyone using Unity 5.6:
In Unity 5.6 the Apply button is enabled for prefabs in play mode, this is a new feature of Unity and unfortunately it does NOT work with Nested Prefabs! Applying changes while in play mode will break your nested prefab connections. Unity itself also throws an exception when applying changes during play mode.
I’ll look into this new feature and see if supporting an Apply button in play mode is something that can be done in the near future.

@tapawafo
The new version (1.1.3) has been submitted to the Asset Store, it should be available soon (usually 1-2 days for updates, but it really depends on the Asset Store Team). If this issue is hindering you with your work and you need the update sooner then please send me a pm with your email address and I’ll send you the update directly.

1 Like

Hi there!

Great to be able to use nested prefabs :smile:

However, we have run into a problem we suspect has something to do with Nested Prefabs. Randomly when we save the scene, Unity freezes for a a couple of minutes before starting to import small assets. This can happen at any time, even after just adding a line of code to a scrip not connected to anything, and then saving. It doesn’t happen every time, which is weird. It’s really tough to work with, as it happens quite often.

Would be great if you had any idea what this could be.

Thanks in advance!

@AndreBengtsson

Thanks for using Nested Prefabs!
Whenever you save a scene Unity will also save all modified prefabs. When Unity saves a prefab, the Nested Prefabs extension will apply these modifications to any nested prefab as well. The ‘Importing small assets’ message here is the prefabs that are being reimported/saved.

This should normally only happen if you have modified a prefab, however it is possible that a script automatically modifies a prefab after it is imported. If this happens the prefab will always be reimported every time you save the scene, if a lot of prefabs are modified like this it will mean every prefab in your project will be reimported.

Please check which prefabs are being imported when you save the scene, the only prefabs that should be imported are any prefabs you have modified and the parent(s) of those prefabs if they are nested somewhere.
You can check which prefabs are being imported with this script:

using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEditor;

public class PrefabImportLog : AssetPostprocessor
{
    public static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths )
    {
        var importedPrefabs = new StringBuilder();

        foreach( string path in importedAssets )
        {
            if( !path.EndsWith( ".prefab", System.StringComparison.OrdinalIgnoreCase ) )
                continue;

            importedPrefabs.Append( "Imported: " );
            importedPrefabs.AppendLine( path );
        }

        foreach( string path in deletedAssets )
        {
            if( !path.EndsWith( ".prefab", System.StringComparison.OrdinalIgnoreCase ) )
                continue;

            importedPrefabs.Append( "Deleted: " );
            importedPrefabs.AppendLine( path );
        }

        foreach( string path in movedAssets )
        {
            if( !path.EndsWith( ".prefab", System.StringComparison.OrdinalIgnoreCase ) )
                continue;

            importedPrefabs.Append( "Moved: " );
            importedPrefabs.AppendLine( path );
        }

        Debug.Log( importedPrefabs.ToString() );
    }
}

Thanks for the info :slight_smile:

Your plugin looks great, just wanted to wish you luck and success in development in maintaining.
Maybe some day I will buy it because unity does not seem to want to create their own solution.

2 Likes

@Visual-Design-Cafe
Hi, I have found an annoying bug:

To Reproduce:

Create two prefabs. At least one prefab should have a child.
3051702--228992--pic1.PNG
Duplicate the child and try to drag it into the other prefab. It also doesnt work if you drag it first out and then into the secound prefab. Importand: There must be two different prefabs.
It only works if the prefabs are the same.
Error Message:

Failed to create Nested Prefab
UnityEngine.Debug:LogError(Object)
VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:RefreshObjectsInSelection(GameObject[])
VisualDesignCafe.Editor.Prefabs.NestedPrefabPostprocessor:OnHierarchyWindowChanged()
UnityEditor.EditorApplication:Internal_CallHierarchyWindowHasChanged()

Through this bug, it is impossible to clone gameobjects from prefabs and to plug into other prefabs.

I hope you find the bug soon!

And if there is time … how far is the progress with the feature of @darky12s post #19/#20?

@IAmJustADog ,

Thanks for reporting this bug. I can confirm that it is indeed broken in the current version. Luckily it has already been fixed in the next update (1.1.4), it should be available sometime this week.

The feature is currently in an experimental state. It seems to be working well and will be send out as a beta version soon (this week or next week). If you are interested in testing the beta version then please feel free to send me a PM and I’ll send you the beta version once it is ready.

Here is a screenshot of what the feature currently looks like:

2 Likes

I just had an unity crash while using this, it’s also a pretty consistent crash.
I moved a script under a different namespace but that script was used on a bunch of objects inside nested prefabs, the whole hierarchy became “broken” (They have a a red X), so I started changing the scripts of all the affected objects but still the x wouldn’t go away.

eventually I figured out that there was a single object still missing the script so I changed it and tried to apply the prefab… and then crash.

I attached the crash log, hoping it helps, if you want to try the project I can give you private access to the repository.

Deleting the affected object seems to have prevented the crash and fixed the prefab.

3052808–229104–crash.zip (48.8 KB)

@MaddoScientisto

Unfortunately this issue is caused by Unity itself. In Unity 5.6 if there is a missing script in a prefab Unity will disconnect all prefab instances, reverting any changes to the prefab will cause a NullReferenceException as well. (The red X means the prefab is disconnected)

The crash should never happen though. I have tried to reproduce this but I can’t seem to get any crash. Breaking the prefab like this, restoring scripts and applying the changes works fine here. It would be great if you could give me access to the repository, the prefab must be broken in a very specific way.

In this case how do I apply parenting a prefab to a child prefab at the root level without changing the child prefab by pressing apply (the default behavior which I kept using thinking it’d apply changes to the root only)

3055005--229371--Screen Shot 2017-05-02 at 3.02.41 PM.png