Save animation at runtime (Standalone)
Hello everyone,
I have searched for hours and coulnd't find a solution, so I'm posing my question here.
I have a 3D model whose arms and legs are moved/rotated via sensors. I can "record" the sensor data and the movements in a proprietary quaternion-data-based format I've developed myself. Replay, pause, etc. works fine.
However, I do want to have an .FBX or at least .anim export at the very end, to use the animation in other programs like 3DSMax or Maya. Therefore, I create an AnimationClip from the movements (actually only rotations), which is not the hard part.
The problem is to export the data to the disk. It has to work in the standalone version (later in mobile version, too), so I can't use AssetDatabase or something similar (SerializableObject) to save the animation clip, as I don't have an Editor.
Can anyone tell me what's the way to go? Any kind of hack or trick is also appreciated, it doesn't have to be nice, it just has to work.
Thanks in advance!
edit 24.11:
So I've done even more research and got deeper into serialization. Unfortunately, it looks if Unity simply isn't made to save stuff in standalone runtime, without using Editor at all. However, my animation IS created during runtime only (due to sensor input) and I need to have it exported SOMEHOW into .FBX.
It doesn't matter if I have to use an external converter to convert from .OBJ (e.g.) to .FBX, but the animation has to be saved as .OBJ first. How could I do that?
All I have discovered so far for animations are serializers writing it down to JSON or other binary format. How could I convert that to .FBX or .anim?
Answer by Magius96 · Nov 23, 2016 at 09:44 PM
I'm not sure that I fully understand what you are going for, so my answer may be totally off, but here it is.
You can save any type of data you want, but you have to determine where to save. In all of my apps I use Application.PersistantDataPath
So let's say you want to store your animations in a folder called "anims" then you might build your path like this:
var path = string.Format("{0}/anims/", Application.PersistentDataPath);
Once you have your path, you can use the standard C# stream classes like BinaryReader, BinaryWriter, TextReader, TextWriter, etc.
Now, if you want to write it as a specific file type, you will need to understand the structure of that file type. Thankfully most file types are fully described somewhere on the internet. If you aren't concerned about your file being opened by other software other than what you are producing, then you can simply make it a binary file and design the structure yourself.
Hi,
thanks for answering. I have done that before frequently, when I implemented my own type of saving animations via .txt-files which store the quaternion data. However, I would need to save in ".anim" (or .FBX, I haven't had a detailed look into that yet), which is the animation format in Unity. I don't know if the format is described in detail somewhere, but I'd rather have a one-line "export clip as .anim" ins$$anonymous$$d of writing a file with the whole format myself.
To clarify: I do create the animation I need in runtime. It works fine when using Editor, because I can save and reload the animation afterwards. But now I need to save the animation from the standalone version.