Answered

Custom FBX export pipeline

Anonymous 2 years ago updated by jasonyak 2 years ago 9

Hi @SoxwareInteractive

Firstly thanks for making such a great and essential tool, we've found nothing else like it on the store.

We've been getting a bit deeper into integrating it into our workflow pipeline and hitting some issues which I was hoping to ask you about to see what workarounds there might be or what we can do differently.

When exporting animations to an FBX we need to be using the option to export to an existing FBX to gain the benefits of an embedded humanoid avatar, however it's undesirable for us that the animation clips are added to the FBX for various reasons and have found no direct way to remove them once they've been added, the only way we have found is by reverting the FBX. The current way we deal with this problem is that we listen for the OnPostprocessAnimation event, once clips hit an FBX we use an editor coroutine to delay a frame and then we export the clip/s into individual .anim files and then revert changes to the FBX, noting that we use a coroutine because we have very limited use any AssetDatabase create or delete methods while post processing events are firing, Unity throws errors if we use these API's during the post processing events. I have tried many other ways during the post processing event to try and intercept the clips from being added or delete them, but nothing seems to work for us, even the integrated Unity way of removing animations via the inspector is as you may know only hiding the sub assets, it's not really deleting the clips.

The main reasons we don't want the FBX increasing in size is because it will end up with hundreds of animation clips, many of which will become outdated animations we no longer need to use. Loading this FBX at runtime will be a drain on memory and it removes our ability to manage which clips are compiled into our apps.

What we ideally wish we could do is a hybrid of your export options where we can choose an FBX containing an avatar to influence the export, but it exports to an individual file rather than being added to the FBX. If that is not possible I was wondering if you have any ideas on how to remove the animation clips UMotion adds or prevent them from being added to the FBX in the first place? we've exhausted ideas trying to solve this and I'm hoping you have a simple solution for us, it would greatly improve our how we use UMotion as part of our tool chain.

Thanks!

Jason

UMotion Version:
Unity Version:
Answered

Hi Jason,

thank you very much for your support request.

The main reasons we don't want the FBX increasing in size is because it will end up with hundreds of animation clips, many of which will become outdated animations we no longer need to use. Loading this FBX at runtime will be a drain on memory and it removes our ability to manage which clips are compiled into our apps.

Afaik, when Unity builds your game, it never includes the raw files (FBX etc.) only the Unity proprietary files that where generated by the Unity editor when importing the e.g. FBX file (i.e. the Unity mesh file, the Unity *.anim file). Furthermore Unity performs checks to see which of these resulting files are used in your project, and is going to strip unnecessary files.

I think Unity's runtime doesn't even "understand" FBX files.

--------


Ok so as I understand your situation, you want to export to FBX but only because you want to benefit from Unity's capability of importing animations with compressed animation curves (something the direct *.anim export of UMotion is not capable of)? You don't care that much about the FBX itself.

You could write a custom export method using UMotion's API.

  1. First of all, create two versions of your FBX file you want to export to:
    "myFbx_noAnimIncluded.fbx"
    "myFbx_temp.fbx" <--- this is the one you define as destination file in the UMotion export settings
  2. Add a menu item to the clip editor's file menu that triggers your custom export script.
  3. In your custom export script, first copy the "myFBX_noAnimIncluded.fbx" over the "myFbx_temp.fbx".
  4. Then trigger the export.
  5. Force Unity to import the *.fbx file now using AssetDatabase.ImportAsset().
  6. Then extract the *.anim file from the Fbx file.
  7. Then copy the "myFBX_noAnimIncluded.fbx" over the "myFbx_temp.fbx" again to get back into your clean initial state.

Here you find the documentation of the UMotion API: https://www.soxware.com/umotion-manual/UMotionAPI.html


Please let me know in case you have any follow-up questions.


Best regards,
Peter

Hi Peter, 

Thanks for the reply, yes we're after a setup where the fbx itself doesn't really matter, we just want to use it's avatar for exporting. The suggested setup is actually pretty much exactly what we have setup. We have a temporary fbx that has our avatar, we export to this, extract the animations, and then we revert the fbx. 


This works, but it then leads to other pipeline issues. We could end up with hundreds of fbx's, each with different avatars and it means we need to be maintaining two fbx's for each fbx we export to. So I was just hoping to pick you brain if you knew of another way which might have this kind of work flow:

- we export to one fbx in the UM export

- animation clips are exported

- but then we can directly remove the animation clips from the fbx file (if possible)

This last line is something I've been unable to work out, it seems the fbx are somewhat tainted once the animations have been exported and added to them. But thought I'd see if you knew any tricks or ways I'm not aware of, I've tried using AssetDatabase.LoadAllAssetRepresentationsAtPath, and then run Object.DestroyImmediate, or AssetDatabase.Delete, or AssetDatabase.RemoveObjectFromAsset but none of them seem to be able to remove the animation clips.

No worries if you're not sure of a way, I just thought I'd try my luck.

Thanks,

Jason

ps: writing back here again after signing in to watch replies to this thread.

My approach should cover your concerns as in point 7) it overrides the FBX with the version that contains no animation data.

Manipulating the FBX directly is not possible via classical Unity API, you would need to use the FBX SDK.

Best regards,
Peter

No worries, yes this approach does work for us. It would have just been neater to find a solution where we didn't have to maintain two FBX's for each fbx we export to. But thanks, it's good to hear from you you think that's just a limitation of the format once something has been added. Probably lesser of two evils to live with a revert process. Thanks.

It would have just been neater to find a solution where we didn't have to maintain two FBX's for each fbx we export to.

You could create the second FBX version only temporary during your custom export process (by duplicating from the original FBX file). But you need to make sure that your export settings in UMotion are referring to the temporary FBX file (the file doesn't need to exist though, just manually type the correct name into the input field).

Best regards,
Peter

Is there by any chance a UMotion API event we could hook into in order to do this? or would we instead have to trigger the export in code which would allow us to run our own pre-export code, but means we can't use the export UI from within UMotion. 

There is currently no way to hook into the default export procedure. But you can add your own menu item to the UMotion UI to trigger your custom export code.

Best regards,
Peter

ok, thank you for that