Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Export FBX at runtime using Autodesk.Fbx?

Discussion in 'Asset Importing & Exporting' started by Zipp, Jul 18, 2019.

  1. Zipp

    Zipp

    Joined:
    Dec 27, 2012
    Posts:
    13
    Hello,

    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):
    1.  
    2. using Autodesk.Fbx;
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    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));
    11.  
    12.         // Export the scene
    13.         using (FbxExporter exporter = FbxExporter.Create (fbxManager, "myExporter")) {
    14.  
    15.             // Initialize the exporter.
    16.             bool status = exporter.Initialize (fileName, -1, fbxManager.GetIOSettings ());
    17.  
    18.             // Create a new scene to export
    19.             FbxScene scene = FbxScene.Create (fbxManager, "myScene");
    20.  
    21.             // Export the scene to the file.
    22.             exporter.Export (scene);
    23.         }
    24.     }
    25. }
    26.  

    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!
     
  2. chanig16

    chanig16

    Joined:
    Jul 4, 2019
    Posts:
    1
    Did you find a solution to this?
     
  3. Drallig

    Drallig

    Joined:
    Oct 28, 2015
    Posts:
    2
  4. George-Ing

    George-Ing

    Unity Technologies

    Joined:
    Jan 14, 2020
    Posts:
    78
    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.

    From looking on GitHub, it seems this is what a few people have done.
    For example: https://github.com/KellanHiggins/UnityFBXExporter
     
  5. poprev-3d

    poprev-3d

    Joined:
    Apr 12, 2019
    Posts:
    71
    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):
    https://github.com/Unity-Technologi...xamples/export/Assets/Editor/FbxExporter06.cs
     
  6. JoystickLab

    JoystickLab

    Joined:
    Mar 18, 2016
    Posts:
    14
    Seems like the exporter does not work on iOS or Android even in 2023. Does anyone have any idea about it?

    I also tried ASCII FBX Exporter, but its giving some error as well.