장민규
장민규

Reputation: 23

How to export game objects in Unity as FBX files (for animations and automatic import)

I am working on exporting a specific game object as an fbx file through Unity.

I have succeeded in creating an fbx file for a single frame using the code below.

However, I have two questions regarding the construction of the desired code.

  1. After exporting to an FBX file, Unity automatically imports the FBX file, and infinite loading occurs during the process. Is there a way to prevent automatic importing?

  2. I want to save game object information from multiple frames by applying certain conditions and use the saved information to create an animated FBX file.

I would appreciate your feedback on the question.

using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Formats.Fbx.Exporter;
using UnityEditor.AssetImporters;

public class ExportFbx : MonoBehaviour
{
    [MenuItem("Tools/Export Modify_origin_edit to FBX (Binary)")]
    public static void ExportFbxFile()
    {
        GameObject obj = GameObject.Find("Modify_origin_edit");

        if (obj != null)
        {
            string filePath = Path.Combine(Application.dataPath, "FBX_file/MyObject.fbx");
            string prefabPath = Path.Combine(Application.dataPath, "FBX_file/MyObject.prefab");

            ConvertToPrefabVariantOptions convertSettings = new ConvertToPrefabVariantOptions
            {
                ExportFormat = ExportFormat.Binary
            };

            GameObject prefabVariant = ConvertToNestedPrefab.ConvertToPrefabVariant(obj, fbxFullPath: filePath, prefabFullPath: prefabPath, convertOptions: convertSettings);

            Debug.Log("FBX ok: " + prefabPath);
        }
        else
        {
            Debug.LogError("error.");
        }
    }
}

Upvotes: 0

Views: 30

Answers (0)

Related Questions