(Using Unity 2021.3.11f1) Today I tried making an AssetPostProcessor for certain FBX files, so that I can give them new data.
My one goal was to give certain skinned meshes access to their pre-skinned vertex positions, put into UV2, which I cannot do outside of unity (as software like blender expects uv to be a vector2, and does not have the capacity unity has to make it a vector3/4).
private void ModifyMesh(Mesh mesh)
{
var vertices = mesh.vertices;
mesh.SetUVs(2, vertices.ToList());
}
Iâve done it in runtime before (example code above), but doing it in runtime is both slower than Iâd like, wasteful on memory, and not as clean to discern where information is coming from, so I determined I should Post Process my FBX imports.
I didnât want to make this happen to all my meshes, as that would be unnecessarily slow.
I didnât want it to be controlled by specific file names as I find those incredibly restricting.
And I didnât want to use asset tags as suggested by this blog post, because the assets already contain user properties that say how they should be handled.
I saw that OnPostprocessGameObjectWithUserProperties exists, and I confirmed that it does detect my FBXâs custom properties. It mentions having full control over the mesh so I figured thatâs great⌠as an experiment - grab a reference to the MeshFilter from a test-cube gameobject, the sharedmesh from that one, and call the method mentioned earlierâŚexcept this introduced a warning that shows up every time I reimport:
Importer(FBXImporter) generated inconsistent result for asset(guid:guidhere)"namehere".
No matter what I try, this warning does not go away. Any type of change I try to make in the method, to the mesh, is met with this annoyance.
I tried exploring other avenues of changing the mesh - perhaps in earlier methods. The information is incredibly scarse and I donât see a single way to obtain the reference to the mesh in any part of the asset post processing pipeline short of getting a component and fetching a shared mesh from that.
Additionally, there is no way to obtain the user properties short of waiting for the exact first method I mentioned, so even if I wanted to use my user properties, I have to wait until that one moment, which seems to have issues.
The research did point out to me that Asset Importers have a userData field, so I could make checkboxes within unity itself and use those from the start of the import process, which sounds incredibly appealing. It is a string so separating it into fields can be a hassle but it also means it is flexibleâŚgreat. Iâll try to extend the model importer editor to have a checkbox for whether my new UVs should be made, writing into userData, and then just check for that to modify my meshâŚ
Except the ModelImporterEditor is internal, trying to make a new editor for it from scratch would be miserable due to the loss of the UI provided by the original, and trying to make a wrapping editor for it extending from AssetImporterEditor is futile because it makes a bunch of incoherent errors despite successful compilations. The most notable one being The previous instance of MyProject.Editor.ModelImporterEditor has not been disposed correctly. Make sure you are calling base.OnDisable() in your AssetImporterEditor implementation.Canât even add a tab to the existing âModel/Rig/Animation/Materialsâ.
So extending the model importer editor is no good, making my own model importer editor is a huge hassle that wonât be maintainable if unity ever updates its own, and is no good, trying to use my already existing user properties already present on the model is no good⌠and Iâm not done yet.
I figured if I canât add new fields to the existing ModelImporterEditor, I can at least make my own desperate window just so I can add userData to the fbx which Iâd like to edit. I went ahead and made my own EditorWindow, which checks the selection for an AssetImporter , and if it finds one, it shows me a checkbox to turn my flag on / off. That worked greatâŚexcept I have one checkbox and the minimum size for an editor window is 100x100. I found the .minSize field, and set it to 10x10, and that worked wondersâŚwhen undocked. I then tried to dock it to the bottom of my inspectorâŚand it was suddenly back to being giant. Some more frustration later and apparently the minsize for docked windows is static and internal, so I canât ever fix that in the current existing version of Unity.
After a few hours of trying everything I can think of, I donât have a single working clean, nor intuitive, nor even functional solution. Itâs incredibly difficult to tell whether the problems are of my own making or actual bugs from unityâs end. Iâd love any type of help I can have in order to make this asset post processing work without stupid warnings, and without heavy compromises like tags, specific path conventions, or permanent window layout space sacrifice.
tl;dr:
- changing mesh data in
AssetPostprocessor.OnPostprocessGameObjectWithUserPropertiesthrows an inconsistent guid warning on every reimport attempt. - User properties cannot be obtained earlier in the asset post processing pipeline
AssetImporter.userDataexists, but there is no easy way to show it nor any other information on Unityâs default asset importer editors, as they are uneditable & unwrappable by any conventional means.- Making an external a separate editor window to set the userData means sacrificing permanent layout space consumption of far too many pixels for the simple cause of a single checkbox.
- The default ModelImporter has 4 tabs, but does not let users add more, despite the many possible and positive use cases.
Today ended in defeat, but I hope this feedback can at least help drive future versions of unity to be far less painful than what I had to go through, and still have to keep searching through, just toâŚadd a checkbox⌠and have it run 2 lines of code on a mesh.
