- Home /
How to store anim files and load them using sqllite?
Hi, I have a feature in a unity based android app that a user can view his/her collection of certain anim files that they have stored in DB.
I have followed this link to learn how to make a DB and store int values in it, but I couldn't find a way to store anim files in DB.
Can anyone guide me in this matter?
I shall be grateful.
Answer by Bunny83 · Dec 02, 2019 at 02:32 PM
Unity's anim files can not be loaded at runtime. They represent an anim asset for the editor. If you want to load / create an AnimationClip at runtime you have to do it manually by creating an AnimationClip and all your corresponding AnimationCurves and use SetCurve to add the curves to your animation clip.
Note that the AnimationCurves of an AnimationClip in a build can not be read out. So if you plan to import / export your animation data at runtime you have to "export" it from the Unity editor using the AnimationUtility class (which is an editor only class) and ship the data in your own custom format (could be a sqlite file)
Keep in mind that a single AnimationClip contains quite a lot structured data. Mapping this in a relational database requires a few tables. Note that I will not write a complete introduction into database layout design and how you could structure that data. If you don't feel like you are ready to pull this off you might want to ask yourselt if this is really necessary.
Thank you so much for your response. This seems like a lot of work and as a beginner, there are many things I don't understand well, like AnimationCurves. But I have one last question for you. Do you think I might pull this off by saving the path of the anim files and by using animator controller I can get all the states and play the specific anim file by getting the name from the path I store?