Unity FBX Exporter - material/textures not embedding properly(?)

Hey,

I’m running some tests with the FBX exporter package. There seems to be an issue with the exporter or my understanding of it.

  • create a cube GO with a specific material in the scene

  • create an FBX from it through FBX Exporter process (“Export To FBX…”)

  • Export Format : ASCII, Include : Model(s) + Animation,

  • dragged the successfully generated .fbx into the scene hierarchy

Instead of two identical cubes showing, the newly dragged into .fbx is all white. If I go into the .fbx inspector and remap the material in the Materials tab, it will appear visually correct.

Can anyone help out and let me know what might be going on here and whether this is expected? Is the .fbx created through the unity exporter not expected to be reused inside Unity possibly?

Thanks in advance

Hi!

Material export is currently limited, especially if not using one of the standard Unity shaders. Therefore the embedded material that is exported and re-imported may not match the original. Remapping the materials to the original Unity materials is the best solution in this case to keep the same material.

What is exported for materials is:

  • Albedo (and texture if present)
  • Emissive color (and texture if present)
  • Specular color (and texture if present)
  • Normal map

If the material has these and they are not exported, it may be a bug. In this case, if possible, please report it from Unity Help > Report a Bug.. menu, including the material and exported FBX.

still have the same problem its not exporting properly

Hi @mrkrrishjoy ,

Which of the material properties are not exporting properly? additionally, which shader is the material using?

The following material and texture properties are currently supported for export:
https://docs.unity3d.com/Packages/com.unity.formats.fbx@5.0/manual/exporting.html#materials

Material export is still limited, however it’s likely a bug if one of the above properties is not exporting properly.

Hello ! I got a solution to focus the Fbx Exporter to Embed Textures with script, and it works for me ! here’s the code :

 public static void ExportGameObject(UnityEngine.Object singleObject)
{
  Type[] types = AppDomain.CurrentDomain.GetAssemblies().First(x => x.FullName == "Unity.Formats.Fbx.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null").GetTypes();
     Type optionsInterfaceType = types.First(x => x.Name == "IExportOptions");
     Type optionsType = types.First(x => x.Name == "ExportOptionsSettingsSerializeBase");
     Type temp = types.First(x => x.Name == "ExportModelSettingsSerialize");
     // Instantiate a settings object instance
     MethodInfo optionsProperty = typeof(ModelExporter).GetProperty("DefaultOptions", BindingFlags.Static | BindingFlags.NonPublic).GetGetMethod(true);
     object optionsInstance = optionsProperty.Invoke(null, null);

     // Change the export setting from ASCII to binary
     FieldInfo exportFormatField = optionsType.GetField("exportFormat", BindingFlags.Instance | BindingFlags.NonPublic);
     exportFormatField.SetValue(optionsInstance, 1);

     // Set the embed textures option to true
     FieldInfo embedTexturesField = temp.GetField("embedTextures", BindingFlags.Instance | BindingFlags.NonPublic);
 
     if (embedTexturesField != null)
     {
         embedTexturesField.SetValue(optionsInstance, true);
         Debug.Log("Embed textures set to true.");
         bool isEmbedTexturesSet = (bool)embedTexturesField.GetValue(optionsInstance);
         Debug.Log("Embed textures actually set to: " + isEmbedTexturesSet);
     }
     else
     {
         optionsType.GetFields().ForEach(f => { Debug.Log(f.Name); });
         Debug.LogError("Failed to set embed textures.");
     }

     // Invoke the ExportObject method with the settings param
     MethodInfo exportObjectMethod = typeof(ModelExporter).GetMethod("ExportObject", BindingFlags.Static | BindingFlags.NonPublic, Type.DefaultBinder, new Type[] { typeof(string), typeof(UnityEngine.Object), optionsInterfaceType }, null);
     exportObjectMethod.Invoke(null, new object[] { filePath, singleObject, optionsInstance });

    Debug.Log(filePath);

}
1 Like