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

Question FBX export/import only supports Vector2 in UV (but the uvs can contain upto Vector4 in Unity)

Discussion in 'Asset Importing & Exporting' started by sabint, Sep 15, 2021.

  1. sabint

    sabint

    Joined:
    Apr 19, 2014
    Posts:
    26
    Hi, I have a procedurally generated mesh in Unity, and I have some Vector4 data stored in UV3 and UV4 that I use for custom shader effects. All is well within the Unity editor, but I want to save the mesh so that I don't have to generate it every time for performance reasons. I tried saving to FBX with the FBX exporter, and importing the resulting FBX. Now, all the UV channels only have Vector2s and I lose half my data.

    I don't know if this is a limitation of the FBX file format, the FBX exporter, or the FBX importer.
    I'd love to hear thoughts from someone who might know more.

    Alternately, is there another file format, where I can save Vector4 in UV channels (or a format that supports arbitrary vertex streams)?

    Thanks
     
  2. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi! It looks like this might currently be a limitation of FBX, which uses Vector2 for the UVs:
    https://help.autodesk.com/view/FBX/2017/ENU/?guid=__cpp_ref_class_fbx_layer_element_u_v_html
    (FbxLayerElementUV based on FbxLayerElementTemplate<FbxVector2>)

    It might be possible to include the additional data as extra information in the FBX, however I don't think it would be loaded by the Unity importer (would potentially need to write a custom importer).

    If you do not need to transfer the data to a different software, an alternative could be saving the Mesh into the Unity .asset format: https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html
     
  3. sabint

    sabint

    Joined:
    Apr 19, 2014
    Posts:
    26
    @vkovec Thanks! Saving to an *.asset file works wonderfully, and I found a github to do just that:
    https://github.com/pharan/Unity-MeshSaver

    Btw, do you know if there's a way to use a different extension for this asset? That would help configuring git LFS, since mesh assets tend to be very large, but I don't really want to blanket enable LFS for every *.asset file.

    Thanks!
     
  4. vkovec

    vkovec

    Unity Developer - FBX Exporter

    Joined:
    Aug 9, 2017
    Posts:
    257
    Hi! glad it works :)

    I think the extension needs to stay the same for Unity to reload it. See supported extensions in CreateAsset: https://docs.unity3d.com/ScriptReference/AssetDatabase.CreateAsset.html

    Maybe a possible solution could be to add to the extension/filename? e.g. foo.mesh.asset
    Or specifying git lfs to track particular files/folders in this case instead of by extension.