Search Unity

Correct way to change UVs on imported fbx mesh via AssetImporter

Discussion in 'Asset Importing & Exporting' started by Xarbrough, Oct 15, 2018.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I'm using
    void OnPostprocessModel(GameObject gameObject)
    to change the UVs of an imported fbx model's mesh at import time through the use of a custom AssetPostprocessor class.

    This appears to be working so far: I reimport my model and the UVs are changed. I can close the editor, reopen, play and everything seems to be working correct.

    However, I noticed that none of my files have actually changed on disk. I have my project checked into external version control (Mercurial) and neither the FBX nor any meta file actually show a change. Also, when opening the project on a different computer, the models don't have the changes. I have to manually reimport everything.

    Is this intended behaviour? That I need to reimport all models on all machines again, or can I somehow store my UV changes made to the FBX mesh?
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Well, I found the issue: By default, there is an option "Optimize Mesh Data" enabled in the Player Settings. The documentation states, that this removes any mesh data (uvs, tangents, colors), which is not used by a material on the model.

    My problem is, that the materials/shaders using my custom UVs are instantiated at runtime and I didn't know about this optimization option being enabled by default. It took my quite some reading and experimenting until I found this very specific case. I still reported it as a bug, because I believe that stripping features should be disabled by default or somehow configurable. At least I should get some kind of report that stripping optimizations have been performed, so I that I notice the error.

    The simplest fix was to disable the optimize mesh data option. Alternatively, it may work if I apply the material at edit time.
     
  3. Teksel

    Teksel

    Joined:
    Jun 13, 2017
    Posts:
    3

    Hey! I was wondering how do you actually force FBX to be saved to disk inside void
    OnPostprocessModel(GameObject gameObject)
    ?
    I did disable Optimize Mesh Data but when forcing FBX reimport by deleting and pasting the file to the same folder, it doest launch all AssetProcessor sequence. Hovewer I don't see any changes in files in Git.
    I read somewhere that you should call
    assetImporter.SaveAndReimport();
    in the end of OnPostprocessModel to save changes in FBX but this doesn't work either.