I want to export my GameObjects at runtime and save it as one FBX on the file system. I am Using Unity 2018.3 HDRP.
I achieved to export it using the FBX Exporter preview package in the Unity Editor. However, it must also work in a Windows Standalone Build. In the documentation of the package I found following info using the Autodesk SDK to export a model also at runtime.
using Autodesk.Fbx;
using UnityEngine;
using UnityEditor;
protected void ExportScene (string fileName)
{
using(FbxManager fbxManager = FbxManager.Create ()){
// configure IO settings.
fbxManager.SetIOSettings (FbxIOSettings.Create (fbxManager, Globals.IOSROOT));
// Export the scene
using (FbxExporter exporter = FbxExporter.Create (fbxManager, "myExporter")) {
// Initialize the exporter.
bool status = exporter.Initialize (fileName, -1, fbxManager.GetIOSettings ());
// Create a new scene to export
FbxScene scene = FbxScene.Create (fbxManager, "myScene");
// Export the scene to the file.
exporter.Export (scene);
}
}
}
However, I do not understand how I can specify the GameObject that has to be exported. Is this even possible in this way or do I understand it wrong?
Furthermore, when exporting the FBX file in Untiy HDRP, the textures in the materials are lost. Do I have to export all materials separately and then assign it again?
I too am looking for a solution for this. The code shown in the first post is the same as the documentation as a “basic exporter” found here (Developer’s Guide | FBX Exporter | 2.0.3-preview.3 (unity3d.com)) but the documentation is vague. Does anyone else have any help for this?
Hey, we don’t officially support an Importer / Exporter that executes at runtime (The FBX Exporter package is Editor only). You’d have to write your own which hooks into the FBX SDK bindings.
You may use the Autodesk.Fbx namespace at runtime in Standalone builds. To do that, according to the doc, you have to do the following:
However, to take advantage of the exporter itself, you’ll have to use the Autodesk bindings available in Autodesk.Fbx and write your own exporter using the mesh/texture objects of Unity.
Some examples are available here (to be modified if you want to make it work at runtime):