Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Export FBX at runtime using Autodesk.Fbx?

Discussion in 'External Tools' started by Zipp, Jul 18, 2019.

  1. Zipp


    Dec 27, 2012

    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.

    Code (CSharp):
    2. using Autodesk.Fbx;
    3. using UnityEngine;
    4. using UnityEditor;
    6. protected void ExportScene (string fileName)
    7. {
    8.     using(FbxManager fbxManager = FbxManager.Create ()){
    9.         // configure IO settings.
    10.         fbxManager.SetIOSettings (FbxIOSettings.Create (fbxManager, Globals.IOSROOT));
    12.         // Export the scene
    13.         using (FbxExporter exporter = FbxExporter.Create (fbxManager, "myExporter")) {
    15.             // Initialize the exporter.
    16.             bool status = exporter.Initialize (fileName, -1, fbxManager.GetIOSettings ());
    18.             // Create a new scene to export
    19.             FbxScene scene = FbxScene.Create (fbxManager, "myScene");
    21.             // Export the scene to the file.
    22.             exporter.Export (scene);
    23.         }
    24.     }
    25. }

    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?

    Thank you for your help!