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

Autodesk.fbx build errors for Windows

Discussion in 'Windows' started by Zipp, Jul 26, 2019.

  1. Zipp

    Zipp

    Joined:
    Dec 27, 2012
    Posts:
    13
    Hello,

    the FbxExporter package from Unity gives the possibility to export GameObjects as FBX files. According to the documentation this is also possible at runtime when implementing the exporter completely using Autodesk.Fbx (the autodesk fbx sdk).

    I achieved now to successfully export the models in the editor. However, when I try to build the application as a Windows Standalone x64, I always get the following error:

    Assets\StandardAssets\FbxExport.cs(5,7): error CS0246: The type or namespace name 'Autodesk' could not be found (are you missing a using directive or an assembly reference?)

    According to the following link it also should work in the build as well:
    https://docs.unity3d.com/Packages/com.unity.formats.fbx@2.0/manual/devguide.html

    Can anybody help me? I already looked into some files of the Autodesk package and I found the NativeMethods.cs script where one can specify the DllImportName as following:

    Code (CSharp):
    1. #if UNITY_EDITOR_OSX
    2.   const string DllImportName = "Packages/com.autodesk.fbx/Runtime/Plugins/x86_64/UnityFbxSdkNative.bundle/Contents/MacOS/UnityFbxSdkNative";
    3. #elif UNITY_EDITOR_LINUX
    4.   const string DllImportName = "Packages/com.autodesk.fbx/Runtime/Plugins/x86_64/UnityFbxSdkNative.so";
    5. #elif UNITY_EDITOR_WIN
    6.   const string DllImportName = "Assets/Autodesk/Plugins/x86_64/UnityFbxSdkNative.dll";
    7. #elif COM_UNITY_FORMATS_FBX_AS_ASSET || UNITY_STANDALONE
    8.   const string DllImportName = "UnityFbxSdkNative";
    9. #else
    10. #error "FbxSdk: C# bindings for this platform haven't been implemented yet, sorry."
    11.         const string DllImportName = "UnityFbxSdkNative";
    12. #endif
    13.  
    14.  
    One can see, that also the UNITY_STANDALONE is supported. I have tried to set a correct path to the dll here, but this did not change anything.

    Thanks for any help!
     
  2. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @Zipp ,

    You shouldn't need to change the path in NativeMethods.cs.

    This looks like an issue with the FBX SDK assembly file being set to editor only. Until we fix this issue, here is a workaround:

    1. Locate the Autodesk.Fbx.asmdef file under packages
    upload_2019-7-26_14-33-5.png

    2. Right click and select "Show in Explorer" option
    upload_2019-7-26_14-34-8.png

    3. In the explorer right click on the Autodesk.Fbx.asmdef file and select "Properties"
    4. In the properties make sure "Read Only" is unchecked
    upload_2019-7-26_14-35-16.png

    5. Open the file in a text editor and under "includePlatforms" remove the word "Editor" and save

    Code (csharp):
    1.  
    2. {
    3.     "includePlatforms": [
    4.         "Editor"
    5.     ],
    6. }
    7.  
    Now if you go back to Unity you should be able to build the project.

    Let me know if this doesn't fix the issue.

    Best,
    Viktoria
     
  3. AlbyDj90

    AlbyDj90

    Joined:
    Feb 7, 2015
    Posts:
    35
    Hi,
    i've got a similar issue that i managed to resolve with your advice but i've got another error when i try to build:
    error CS0234: The type or namespace name 'Formats' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?).
    I tried to apply the same procedure but Unity.Formats.Fbx.Runtime.Asmdef is different:

    Code (csharp):
    1.  
    2. {
    3.     "name": "Unity.Formats.Fbx.Runtime",
    4.     "references": [],
    5.     "optionalUnityReferences": [],
    6.     "includePlatforms": [],
    7.     "excludePlatforms": [],
    8.     "allowUnsafeCode": false,
    9.     "overrideReferences": false,
    10.     "precompiledReferences": [],
    11.     "autoReferenced": true,
    12.     "defineConstraints": [],
    13.     "versionDefines": []
    14. }
    15.  
    How can i resolve this?
    Thanks

    EDIT: I see the problem is that i cant use something in the UnityEditor namespace...so the example script for exporting FBX models in the dev guide is no use for me.
    There is a way for export some objects in a FBX file like that example but in runtime? I cant find anything...
     
    Last edited: Oct 18, 2019
  4. Dist0

    Dist0

    Joined:
    Oct 28, 2017
    Posts:
    15
    Hi,
    This doesn't seems to be a valid fix. Dll was not found when using all 3.0 packages. I've to revert back to earlier 2.0 version in order to work without weird package modification. (by Scripting and on editor, it's the same)
    Also why the ModelExporter class from the Api implement IDispose while the class only have a static method Model.Export() and don't have any instance stuffs? => https://docs.unity3d.com/Packages/c...ditor.Formats.Fbx.Exporter.ModelExporter.html
    The documentation lack? Or that's this kind of thing who make that's stay on preview... I've maybe missed something, but why do you publish a preview package when her main feature doesn't work on the main target platform ?
    Sorry, but some time lost for nothing, really.
     
  5. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @AlbyDj90,

    Unfortunately the FBX exporter does not currently support export at runtime. However, you could use the FBX SDK C# bindings (com.autodesk.fbx package) to write your own runtime exporter. There is a simple example of an exporter in the developer guide: https://docs.unity3d.com/Packages/com.unity.formats.fbx@3.0/manual/devguide.html.
    You can also reuse several of the functions from the FBX exporter (Packages/com.unity.formats.fbx/Editor/FbxExporter.cs file) for exporting different types of objects/components.

    Hope this helps,
    Viktoria
     
  6. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @Dist0,

    Sorry to hear this is still an issue with the 3.0 packages, we had pushed a fix in version 3.0.0. Which version of Unity were you using? Also which platform are you targeting?

    As for the API documentation, there are additional functions in the ModelExporter class, however they are not currently documented/exposed for use. You can check out the full implementation either in the Packages/com.unity.formats.fbx/Editor/FbxExporter.cs file in your project, or on the GitHub: https://github.com/Unity-Technologi...w/com.unity.formats.fbx/Editor/FbxExporter.cs.

    Best,
    Viktoria
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    I had the same issue with package 3.0.x and latest LTS. I had to revert back to 2.0.x versions of the package.
     
  8. hungrybelome

    hungrybelome

    Joined:
    Dec 31, 2014
    Posts:
    336
    Same issue with 3.0.1 preview on a Mac.
     
  9. RegisVe

    RegisVe

    Joined:
    Mar 2, 2018
    Posts:
    34
    have the same issue on Mac Unity 2019.3.2 fbx exporter 3.0.1
     
  10. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    AcidArrow likes this.
  11. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
  12. abhishekm942

    abhishekm942

    Joined:
    Oct 18, 2019
    Posts:
    10
    I still get the error "The type or namespace name 'Formats' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)" when building for standalone windows. I tried deleting "Editor" from Autodesk.fbx.asmdef but the error wont be fixed.
    I am using Unity v2019.4.0f and FBX exporter v3.2.1 preview.2
     
  13. sba_stuff

    sba_stuff

    Joined:
    Feb 17, 2018
    Posts:
    1
    I Managed to export the fbx file, But it is empty. When I am in the scene at runtime and hit the F key, the scene is exported, but it is empty. When I open the scene in blender it has nothing. What did I did wrong?
     

    Attached Files:

  14. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @abhishekm942,

    Are you trying to call functions from the FBX exporter at runtime?
    The FBX exporter is currently editor only and does not support export at runtime.
    For exporting at runtime you could use the FBX SDK C# bindings (com.autodesk.fbx package) to write your own runtime exporter. There is a simple example of an exporter in the developer guide.
    For exporting different types of objects/components you could reuse some of the functions from the FBX exporter.

    Best,
    Viktoria
     
  15. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @sba_stuff ,

    Your code is correct, however the example in the developer guide is only for exporting an empty scene.
    You will need to add functionality for exporting different objects/meshes/materials at runtime.
    For example you can use the FBX exporter for reference and reuse functions depending on what you would like to achieve.

    Best,
    Viktoria
     
  16. razzraziel

    razzraziel

    Joined:
    Sep 13, 2018
    Posts:
    395
    @vkovec

    Yea but empty scene doesn't help too much. Maybe you can consider having an example for a few simple objects to export. I wouldn't call it a guide unfortunately. FBX Exporter is too crowded script (4.5k lines) and trying to figure out for runtime exports is taking too much time.
     
    Last edited: Mar 25, 2021
  17. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @razzraziel ,

    Thank you for your feedback, I've logged a task to add more examples to the docs.
     
  18. cicvatom

    cicvatom

    Joined:
    Mar 11, 2020
    Posts:
    5
    Hello,

    I feel like the issue i have is similar to the ones before.
    I am currently trying to search for materials that are in the fbx file by using FBX SDK in the editor. The conversion that is in Unity is insufficient for me, most of the information is lost with default conversion and I want to save it for later usage. I tried looking at the documentation and examples, but it did not help.
    The issue I have is that I can find only one material, I cannot find all of them. Many methods that I think are useful for the search require some ID or string, and I can have a fbx file with dozens of materials ...
    Is there a way to use the FBX SDK to iterate through all the materials in the imported fbx file?
     
  19. cicvatom

    cicvatom

    Joined:
    Mar 11, 2020
    Posts:
    5
    I would like to add that the root node of the fbx file scene has zero children and I do not see a way to access the graph.
     
  20. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi @cicvatom ,

    With the FBX SDK it should be possible to call fbxScene.GetMaterialCount() to get the material count, then use GetMaterial(int pIndex) to get each material.
    The same can be done for FbxNode's by iterating over the nodes and calling fbxNode.GetMaterialCount() then GetMaterial(int pIndex).

    However, the exposed import functionality is currently limited, and the GetMaterialCount() functions are not currently exposed to C#. I will log a task for this.

    In the meantime, to expose additional functionality, including these functions and any others you may need, you can follow these steps:

    Get the source code from GitHub:
    https://github.com/Unity-Technologies/com.autodesk.fbx

    In the Source/ folder, you can find .i files which determine which classes and functions are exposed.
    You can edit fbxnode.i for example to include GetMaterialCount() by adding the following line:
    Code (csharp):
    1.  
    2. %rename("%s") FbxNode::GetMaterialCount;
    3.  
    Then follow the instructions in the README to recompile the package.

    Add the updated package to your Unity project and you should now have access to the functions you added.

    Pull requests are welcome if you would like to share your changes.

    Would it be possible to share the FBX file? Does the file otherwise import correctly with the child nodes in Unity?

    Best,
    Viktoria
     
  21. cicvatom

    cicvatom

    Joined:
    Mar 11, 2020
    Posts:
    5
    Hello,

    thank you for the answer.
    To summarize my trial and error workflow:
    - I tried GetMaterialCount() / GetMaterial(index), although without the suggestions you presented in your reply.
    - I tried to iterate through properties as well, but there were no materials,
    - and GetRootNode() method, that had no children, as I wrote earlier.

    The file gets correctly imported via drag and drop.

    Thank you very much for your help
     

    Attached Files:

    Last edited: Apr 13, 2021
  22. cicvatom

    cicvatom

    Joined:
    Mar 11, 2020
    Posts:
    5
    Hello,

    thank you for your help. I managed to get the cloned library working.
    I realized that there was a mistake in the code I have written. I overlooked one line in the examples, now the FBX library is working as it should.

    Thank you
     
    vkovec likes this.
  23. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    521
    Any actual useful example on how to export a gameobject at runtime?
     
  24. DarwinVS

    DarwinVS

    Joined:
    Mar 11, 2020
    Posts:
    1
    hello, trying to build (com.autodesk.fbx github)
    following the readme, but I get this error, how can I solve it
     

    Attached Files:

    • Help.png
      Help.png
      File size:
      55.6 KB
      Views:
      157
  25. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi! this might be a bug in the CMakeList.txt that happens if the default CMAKE_OSX_ARCHITECTURES value is used (setting it to a list instead of a string). Will log a bug to fix this.
    Are you running the CMakeList directly? if so have you tried running `python build.py` instead? The build.py script does some additional setup and should avoid this issue.

    Alternatively until it is fixed you can try locally changing this line to use "arm64" instead of "arm64;x86_64": https://github.com/Unity-Technologies/com.autodesk.fbx/blob/release/4.1/CMakeLists.txt#L29
     
    deadlycrow likes this.
  26. deadlycrow

    deadlycrow

    Joined:
    Feb 10, 2014
    Posts:
    166
    So its 2024 and all those errors about Fbx exporter are still happening, i just upgraded my project to unity 2022.3.18.f1 version, and everything was fine, THEN i closed the project and started it again and now my console is full of fbx errors. And it wont let me work even, I cant just clear the console and keep working, the engine just wont compile. Any idea? its insane. 131 errors in multiple different scripts of the package (Library\PackageCache\com.autodesk.fbx@4.2.1).
     
    Last edited: Feb 3, 2024