Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Bug?] Materials-folder does not get generated when importing files

Discussion in '2017.3 Beta' started by BUWbrean, Nov 23, 2017.

  1. BUWbrean


    May 4, 2017

    When I try to import fbx or obj-files in the Beta the Unity Editor does not create the Materials-folder but instead forces the standard materials for the imported materials. Because of performance issues I need to change the material for Hololens Development (to Holotoolkit/FastConfigurable) and can not use standard. In 2017.2.0f3 the Materials-folder gets created.
  2. bogdancoder


    Unity Technologies

    Feb 6, 2017

    Importing materials as sub-assets is the new default in Unity starting with 2017.3.

    You have several options for reproducing the legacy behavior, which involve creating an asset postprocessor:

    1. If you already have a library of materials that you want to use, you can use the SearchAndRemapMaterials() method of the ModelImporter. See the example here:

    2. If your material library is not complete and you'd like to extract new materials from the imported assets, you can write an asset post processor as follows:

    Code (CSharp):
    1. class MaterialExtractorPostprocessor : AssetPostprocessor
    2. {
    3.     public static void OnPostProcessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    4.     {
    5.         var materialsPath = "Assets/Materials";
    6.         Directory.CreateDirectory(materialsPath);
    7.         var assetsToReload = new HashSet<string>();
    8.         foreach (var assetPath in importedAssets)
    9.         {
    10.             if (assetPath.ToLower().Contains(".fbx"))
    11.             {
    12.                 var importer = AssetImporter.GetAtPath(assetPath) as ModelImporter;
    13.                 var materials = AssetDatabase.LoadAllAssetsAtPath(importer.assetPath).Where(x => x.GetType() == typeof(Material));
    14.                 foreach (var material in materials)
    15.                 {
    16.                     var newAssetPath = string.Join(Path.DirectorySeparatorChar.ToString(), new[] { materialsPath, }) + ".mat";
    17.                     var error = AssetDatabase.ExtractAsset(material, newAssetPath);
    18.                     if (string.IsNullOrEmpty(error))
    19.                     {
    20.                         assetsToReload.Add(importer.assetPath);
    21.                     }
    22.                 }
    23.             }
    24.         }
    25.         foreach (var path in assetsToReload)
    26.         {
    27.             AssetDatabase.WriteImportSettingsIfDirty(path);
    28.             AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
    29.         }
    30.     }
    31. }
    3. If you would like to just preserve the old behavior, no questions asked, you can set the ModelImporter.materialLocation property to External in a similar asset postprocessor. This option has the drawback of making your imports non-deterministic and will be removed in future releases.

    Hope this helps!
    Kolgrima and BUWbrean like this.
  3. OllyNicholson



    Jun 17, 2011
    The third option would be to use the new (well 2017.2) Materials tab and select Use External Materials (Legacy) on the imported file - we hope to have that in the documentation ASAP

    Attached Files:

    BUWbrean and Peter77 like this.
  4. bogdancoder


    Unity Technologies

    Feb 6, 2017
    One more option is to continue to use the embedded materials and to remap them to the ones in your library using the Search and Remap button on the Materials tab.
    soufiane159 and BUWbrean like this.