Search Unity

How to edit multiple prefabs at once?

Discussion in 'Prefabs' started by Peter77, Dec 9, 2018.

  1. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,595
    I'm trying to create a small project for a bug-report and would like to remove a "Pickup" Component from various prefabs, but Unity 2018.3 does not seem to allow me to do this anymore.

    Prior 2018.3 I was able to select multiple prefabs in the project and if those prefabs had the same Component, it would show up in the Inspector and I could remove this Component from all prefabs with a single click.

    In 2018.3, it seems I need to edit each individual prefab in the "prefab edit mode window", which is for this particular type of work much more overhead than it was before.

    What am I missing here? How can I edit multiple prefabs in the project at once, like in 2017.4 for example?
     
    joshcamas, erenaydin, Rich_A and 2 others like this.
  2. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    1,991
    It works for me. In 2018.3.0b12, I created a cube, added components to it, dropped it into a prefab folder then duplicated it in the hierarchy view. I selected the multiple objects and was able to remove components in the inspector.

    Now, in case you have three identical prefabs in the prefab folder (why would you?) and you select all of them at the same time, you cannot edit them simultaneously (I don't think you could do that in the previous versions). You cannot edit multiple prefabs at the same time, whether they are identical or not. :)
     
  3. Peter77

    Peter77

    Joined:
    Jun 12, 2013
    Posts:
    3,595
    Thanks for your answer.

    It does work in the hierarchy, but I was referring to having multiple prefabs in the project, where each has the same component with just different values.

    2018.3 does not allow to edit those different prefabs, which are located in the project browser rather than the hierarchy, at once.

    Reproduce
    • Click "File > New Scene"
    • Click "GameObject > 3D > Cube"
    • Drag&Drop Cube from Hierarchy to Project to create a prefab from it
    • Click "GameObject > 3D > Sphere"
    • Drag&Drop Sphere from Hierarchy to Project to create a prefab from it
    • Select Cube and Sphere prefabs in Project
    Observe Unity does not allow to modify the selected prefabs at once. The "Open Prefab" button is disabled and the the Inspector does not show the Components too.

    I can't remove the "Mesh Renderer" for example from both prefabs at once anymore, I need to open each one individually.

    This used to work in Unity prior 2018.3 with the overhauled prefab workflow.
     
    Last edited: Dec 9, 2018
    Rich_A, NexTGeNDeV and Artaani like this.
  4. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    1,991
    I just verified in 2018.2 and it worked as described but now with 2018.3, you can open each prefab in a scene view to actually see and modify its content. You can no longer open several different prefabs at the same time.

    I didn't like it much either at the beginning, now I'm getting used to it. Before, you couldn't access some components in a prefab that contained many children that themselves had children, now you can. ;)

    Prefab open in its own scene

    Capture2.JPG

    Several prefabs selected at the same time

    Capture.JPG
    Edit: in any case, do not file a bug report for this, it's not a bug. :)
     
    Last edited: Dec 9, 2018
    erenaydin and Peter77 like this.
  5. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    596
    for three objects this would work, but sometimes you have more than just a few
     
    ricna-net likes this.
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    3,616
    This is really the textbook case of Prefab Overrides. Your prefabs should not be independent, they should be overrides and inherit from one another.
    The new workflow is well, new, we have to get used to it. :D
     
  7. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    596
    But even there is the case where the differences you'd want to equalize with multi-editing are overrides.
    Maybe if the prefab stage allowed to open multiple objects like a multi-scene sceneview that could be a way to then multiselect and adjust them, because if i'm not mistaken, multiselect in the prefab stage hierarchy still works as usual.
     
  8. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    403
    People can get used to any degradation of system. It does not means that degradation is okay.

    Why I can't edit a prefabs which consist of single GameObject? This have no any sense.
    This is not a feature, and we should not get used to it, this is a bug which should be fixed.

    The "best" way which I found:
    1. Select prefabs and drag it into scene view
    2. Edit what you want
    3. Press "Delete" on keyboard
     
    Last edited: Dec 11, 2018
  9. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    1,991
    No big deal really. You people like to rant for anything.

    It's absolutely not a "degradation"; with the new system you can edit prefabs more precisely and, as I already said, in the previous versions, you couldn't access all the components of the prefab without having to create them on the scene; now you can.

    Maybe one day opening several prefabs on one unique scene will be possible and you'll be able to do whatever you want with them.
     
  10. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    403
    In previous version we were able to access all components of the prefab on its root object and on all children located 1 level deep.
    If we need game objects located 2 level deep or deeper - in that case, yes, we need to drag prefab in the scene.

    No, we can't. Now we can't edit prefabs without dragging it in the scene, even if it have only a single object without any children.

    What button "Open prefab" do - it is actually creates a temporary scene and spawn a prefab in this scene for you.

    Another interesting fact. If we will open prefab file with the Notepad, we will see that previously prefab had human-readable format. But the new version of prefab file looks like a binary file and can't be human-read.
    What is more important, it can't be read by serializer of Unity Inspector. This is why it didn't work anymore.
    Technically prefab files now similar to scene files, it is just a pure binary data.

    Another unpleasant effect from such changes, if you are using version control system such as GitHub and SourceTree, you no longer can see a changes made over prefab. But earlier it was possible to see what data in prefab file was changed. Sure big teams will be unhappy with that.

    And another interesting fact. Seems like the asset called Nested Prefabs provided the same possibilities without breaking of existed prefab format and workflow.

    -------------

    But overall, all disadvantages of new prefab system is not serious and can be acceptable, yes.
     
    Last edited: Dec 11, 2018
    llJIMBOBll, Rich_A and Romenics like this.
  11. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    436
    This is not true. If you have the editor set up to serialize as text prefabs are also text and easily readable.
     
    APSchmidt likes this.
  12. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    1,991
    Thank you for your reaction; maybe you could elaborate on the rest of @Artaani's ramblings? :)
     
  13. TX128

    TX128

    Joined:
    Aug 22, 2018
    Posts:
    24
    The new way Unity handles this makes no sense.

    Editing multiple prefabs at the same time is a core feature we were using all the time. Now we need to go prefab by prefab editing properties, which is more error prone and actually doesn't offer any significant advantatge.

    Not being able to accces first levels properties doesn't make much sense either if you ask me.
     
  14. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    141
    I agree. I am staying with 2017.4 LTS until this issue has been fixed.

    Core functionality should not be added on one hand and then removed on the other.

    The BETA program should be reviewed if this is the outcome, because all of these issues were highlighted by testers in the forums here, and yet the functionality was released into the wild anyway.
     
  15. Bravo_cr

    Bravo_cr

    Joined:
    Jul 19, 2012
    Posts:
    148
    Just to put my 2 cents here. Exactly the same issue. But not only for editing, what if you just want to go over a number of prefabs checking the state of some variable?, you have to click one by one and open it. Also, you can't have two prefabs opened at the same time (with the inspector locked).
     
    erenaydin and Rich_A like this.
  16. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    637
    I have hundreds of prefabs, with a component that I need to add and edit together. One key gain in having components in the first place is multiselect, where even though the selected objects aren't identical, you can edit whatever components support multiselect.
     
    erenaydin likes this.
  17. dvoidis

    dvoidis

    Joined:
    Apr 11, 2016
    Posts:
    3
    Cant agree more, i have hundreds of separate prefabs for items etc, and with 2018 its a PITA to not be able to easily go over them and check & tweak values. There is no reason why you should not be able to edit the root object scripts like you could before. Except ofc lazy developers. Yet another reason to stay with 2017 :(
     
    joshcamas, erenaydin and Rich_A like this.
  18. erenaydin

    erenaydin

    Joined:
    Mar 1, 2011
    Posts:
    365
    I have 250+ prefabs which needed to be a transform edit.

    I'm wondering if no one asked about this while developing the new prefab workflow. I mean every developer has needed it.
    This is the first bad update from Unity.

    Now we need to code to edit multiple prefabs...

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. using System.IO;
    6. using System.Linq;
    7. using System.Reflection;
    8.  
    9. public static class PrefabLoader
    10. {
    11.     public static List<GameObject> LoadAllPrefabsOfType(string path)
    12.     {
    13.         if (path != "")
    14.         {
    15.             if (path.EndsWith("/"))
    16.             {
    17.                 path = path.TrimEnd('/');
    18.             }
    19.         }
    20.  
    21.         List<FileInfo> files = new List<FileInfo>();
    22.         DirectoryInfo dirInfo = new DirectoryInfo(path);
    23.         DirectoryInfo [] directories = dirInfo.GetDirectories();
    24.  
    25.         foreach (DirectoryInfo dInfo in directories)
    26.         {
    27.             FilesInDirectory(dInfo, ref files);
    28.         }
    29.  
    30.         List<GameObject> prefabComponents = new List<GameObject>();
    31.  
    32.         //loop through directory loading the game object and checking if it has the component you want
    33.         foreach (FileInfo fileInfo in files)
    34.         {
    35.             string fullPath = fileInfo.FullName.Replace(@"\", "/");
    36.             string assetPath = "Assets" + fullPath.Replace(Application.dataPath, "");
    37.             prefabComponents.Add ((GameObject) AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)));
    38.         }
    39.  
    40.         return prefabComponents;
    41.     }
    42.  
    43.     public static void FilesInDirectory(DirectoryInfo dInfo, ref List<FileInfo> assets)
    44.     {
    45.         assets.AddRange (dInfo.GetFiles("*.prefab").ToList ());
    46.         foreach (DirectoryInfo inf in dInfo.GetDirectories())
    47.         {
    48.             FilesInDirectory(inf, ref assets);
    49.         }
    50.     }
    51. }
    52.  
    53. public class TransformToZero : EditorWindow
    54. {
    55.     // Add menu named "My Window" to the Window menu
    56.     [MenuItem("fix/TransformToZero (Assets/Bundles/ folder)")]
    57.     static void Init()
    58.     {
    59.         List<GameObject> identities = PrefabLoader.LoadAllPrefabsOfType ("Assets\\Bundles\\");
    60.  
    61.         foreach (GameObject gameObject in identities)
    62.         {
    63.             string path = AssetDatabase.GetAssetPath(gameObject);
    64.             GameObject go = PrefabUtility.LoadPrefabContents(path);
    65.            
    66.             // Do you edit here.
    67.             go.transform.position = Vector3.zero;
    68.  
    69.             PrefabUtility.SaveAsPrefabAsset(go, path);
    70.             PrefabUtility.UnloadPrefabContents(go);
    71.         }
    72.  
    73.         AssetDatabase.SaveAssets();
    74.     }
    75. }
    76.  
     
    TokyoWarfareProject and Rich_A like this.
  19. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    403
    joshcamas, Rich_A and erenaydin like this.
  20. drakeskywing

    drakeskywing

    Joined:
    Jan 28, 2019
    Posts:
    1
    So being new to unity, I discovered this annoying "feature" while following the https://unity3d.com/learn/tutorials/s/2d-roguelike-tutorial which in the version they pushed out reference the ability to update multiple prefabs simultaneously, only for me to discovered this didn't appear to be the case anymore.

    Seeing the variety of comments and distastes for the removal of this feature, I get both sides.
    In saying all that, I think that this shift in prefab workflow makes sense from a development standpoint, as there are a number of optimizations I can see Unity doing on the side with inheritance tree's that would lower certain overheads, as well to some extent speed up development if you embraced this design pattern from the get go.

    For existing projects though, especially those which have alot of prefabs, each with minor tweaks I can only imagine the nightmare this will introduce, and personally I think they should have had a phase over version, where they clearly communicated, this feature is deprecated, so start migrating now otherwise you aren't going to have a good time when we yank it.

    Thanks to all for the clarification
     
    protopop and Rich_A like this.
  21. MattDavis

    MattDavis

    Joined:
    Aug 11, 2013
    Posts:
    9
    I've also just come across this. I really like the new prefab workflow but consider this an issue.

    Wouldn't the ideal solution be to have the new "Open Prefab" button in the inspector, but also show the first-level GameObject components underneath for simple edits and multi-editing?
     
    erenaydin likes this.
  22. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,588
    2 days ago i upgraded to 2018.3.3 and i thought it was not possible to edit multiple prefabs at the same time. But i found out if i drop all prefabs on the scene, i can edit their properties and then click on Overrides-> Apply all
     
  23. unity_VdapkEACFQIl6Q

    unity_VdapkEACFQIl6Q

    Joined:
    Feb 5, 2019
    Posts:
    1
    Thanks! It took me a while to find this option but it works like a charm. Now I don't have to do the prefabs one by one and can simply add them to the hierarchy, update them, and delete them from the scene when done updating them with the Override All option.
     
  24. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    267
    God, I just hate this new prefab system. They ruin everything. Now, for just simple edit prefab in game window, I need to switch forward and backward between this stupid prefab windows. You can't just delete something on prefab in the scene now, you just can't do nothing. You can't see children of prefab in assets, before I can add script and it's work when object appear in the scene (in the editor) and then script delete itself, now I can't do this. Stupid upgrade. Old prefab system was just fine.
     
    Last edited: Feb 9, 2019
    jrumps, erenaydin and Rich_A like this.
  25. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    284
    New prefab system workflow feels as if it was designed by a crew of chimps on crack. The very worst is that prior to its implementation they where warn of the limitations and workflow issues and no one at dev team gave a ****. It is making my everyday work a pita and can't roll back because the rest of the release i great.
     
    jrumps, j04milan, erenaydin and 2 others like this.
  26. chaseholton

    chaseholton

    Joined:
    Dec 17, 2012
    Posts:
    51
    I do have to say, the only shortcoming to the new prefab system is the lack of multiple prefab editing from within the project folder. Something I used so often in games with many prefabs like item pick ups and the like. I'm making do, but it is baffling why I can't just highlight a bunch, drag in that particle effect they all need and call it a day.
     
  27. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    284
    they say its IMPROVED so donn´t complain :D
    _________________________________________

    It the new prefab in the middle of a cycle wasnt catastrofic enough, a couple of days ago unity wan that there is a security flaw on the editor, kind of backdoor, so you basically have to choose wether saty safe or keep your prefab workflow :D , bravo

    --------------------------------------------------------------------
    They also made fbx like files behave like prefabs, with all the annoyances but without the benefits of making theese instantiatable directly, bravo again.
     
    id0 and jrumps like this.
  28. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,588
    For the future baffled people, the answer to the question is on #22
     
    boorch likes this.
  29. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    284
    I did miss that!! its a bit hacky but cool!!
    Anyone using Photon networking beware of this aproach tho, you'll need to make an script that DOES RESET ID before overwriting the changes back
    While not as confortable as before it is WAAAY Better than going 1 by 1
     
  30. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    1,991
    Yep, that's the fix, for now.

    There is still the possibility that opening several prefabs on a unique prefab scene could be added to further versions though.
     
  31. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,558
    APSchmidt likes this.
  32. RakNet

    RakNet

    Joined:
    Oct 9, 2013
    Posts:
    107
    The preview build suggested by runevision is out of date.

    The best solution at the moment is to multi-edit prefabs in the scene view, then Apply All.

    upload_2019-3-28_10-24-4.png

    In large projects it is cumbersome to drag each object by hand into the scene. This script will do it for you via multi-select

    Code (CSharp):
    1. [MenuItem("Assets/Util/Instantiate Selected", false, 2351)]
    2.     private static void InstantiateSelected()
    3.     {
    4.         GameObject[] selectedObjects = Selection.gameObjects;
    5.         foreach (GameObject selectedObject in selectedObjects)
    6.         {
    7.             PrefabAssetType pat = PrefabUtility.GetPrefabAssetType(selectedObject);
    8.             if (pat == PrefabAssetType.Regular || pat == PrefabAssetType.Variant)
    9.             {
    10.                 GameObject objSource = (GameObject)PrefabUtility.InstantiatePrefab(selectedObject);
    11.             }
    12.             else
    13.             {
    14.                 Debug.Log("Skipping " + selectedObject.name + ". GetPrefabAssetType returned " + pat.ToString() );
    15.             }
    16.         }
    17.     }
     
    erenaydin likes this.
  33. Wood-Innis

    Wood-Innis

    Joined:
    Jun 3, 2014
    Posts:
    1
    I'm trying to copy transform data from one prefab to another. None of the posted solutions so far have been helpful because Unity won't apply scene references to prefabs. I can't seem to find any alternative solutions either.
     
  34. Mystic_Quest

    Mystic_Quest

    Joined:
    Feb 22, 2016
    Posts:
    38
    Some say the changes were a degradation, others an improvement. The thing is that they can be both. Yes, sure there are improvements, but the lack of intuitiveness in the new prefab editor is staggering.

    I used to be able to add a component to dozens of prefabs in a few seconds in a clean way, am I now supposed to have to bloat my script number and do it with overrides? Wanted to drag a prefab's children on another prefab's script the other day and while I used to be able to do that with a simple drag and a click on "inspector lock" in a couple of seconds, I had to find a messy workaround that involved finding them via script again, since "lock" is overridden when a prefab is opened. Now I want to edit some prefabs fast in correlation with the scene, must I instantiate every one of them in the scene to do that, adjust them and then override?

    Please, by all means, keep the new functionality and improvements, but don't make basic things harder or more time-consuming than they currently are. Ever.
     
    Rich_A and TokyoWarfareProject like this.
  35. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    284
    I still keep dreaming that they will release 2018.4 LTS with legacy prefab system. Do it and I will regain faith in this engine.
     
  36. itsGTAWWEKID

    itsGTAWWEKID

    Joined:
    Oct 19, 2018
    Posts:
    2
    I'm uses to selecting all my prefabs in a folder and adding a mesh collider to all of them after a large import. Now i can't do that because it wants to open the prefabs which wont allow me to open all of them. Yet I can select the entire scene and add a mesh collider to everything include cameras?
     
  37. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    284
    in 2019 they allow now to edit prefab on inspector view by selection on project view, AND (just tested) they allow for MULTIPLE PREFAB EDITING AS IT WAS BEFORE!
    I accept that as an apology Unity, I accept it. It may not come to 2018.4 LTS, hopefully it does, YET. annoyances remain like you cant change hyerarchy and all that crap
     
  38. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    141
    I wonder what the actual interest in 2018.4 LTS will be...

    If you are at the end of a 2 year+ project (like me) you are still on 2017.4 which has compatibility with so many great old assets.

    If you have been using the new systems (shader graph, SRP, etc etc.) you will be switching to 2019.x to get those systems out of preview.

    If you've been using 2018.x for major development, but the prefab system changes (even with improvements) still fundamentally break your project, you'll stick with 2018.2.

    2019.4 looks to be the next great release for long-term support and development.
     
  39. TokyoWarfareProject

    TokyoWarfareProject

    Joined:
    Jun 20, 2018
    Posts:
    284
    I will use LTS.
     
  40. TX128

    TX128

    Joined:
    Aug 22, 2018
    Posts:
    24
    2019.1 has introduced a problem with one of our shaders that we can't seem to even bother to try to point down. So we just downgraded to 2018.3.11 and upgraded to 2018.3.13 while waiting for 2018.4. It is a pitty that we can't use 2019.1
     
  41. Greyborn

    Greyborn

    Joined:
    May 26, 2016
    Posts:
    28
    We're close to finishing our game's console ports and need to stay on 2018 LTS for this project. I won't hold my breath, but the ability to mass edit prefab values like they added in 2019 would be a very welcome fix for 2018 LTS and has our vote. It just so happens that we need to modify some optimization settings on many hundreds of environment prefabs now and could really use this functionality.