Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to save an animation clip on IOS device

Discussion in 'Scripting' started by Leos-Clockworks, Feb 19, 2020.

  1. Leos-Clockworks

    Leos-Clockworks

    Joined:
    Oct 27, 2017
    Posts:
    4
    I been trying to save an animation clip on run time.
    it works fine on editor using

    Code (CSharp):
    1. AssetDatabase.CreateAsset(clip, path);
    But the problem is that AssetDatabase isn't something used with IOS so i cant build with it.
    I tried looking for many solutions but i didn't find anything that points to how it is possible to do such a thing.
    Saving it as a byte array isn't working for me cause i didn't find a valid way to turn an animation clip into one.

    i strongly believe that there must be a way to save an animation clip straight to the asset folder.

    Any help would be much appreciated!
     
  2. TheDevloper

    TheDevloper

    Joined:
    Apr 30, 2019
    Posts:
    18
    Following
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    8,471
    Interesting belief. However, animation clips as YAML files exist only between your on disk assets and the Unity editor.

    After that they are mulched down to whatever native data format is best for the target platform.

    If you want to write an animation clip out to disk at runtime, you would need to basically serialize change-over-time information from whatever GameObjects you want to record the animation of. Then you would need to read that into Unity at EDITOR time, and create an animation out of it.

    If you just want to save the animation data temporarily and replay it during the same session, then it becomes even easier since you don't need to save it anywhere.
     
    jipsen and TheDevloper like this.
  4. jipsen

    jipsen

    Joined:
    May 22, 2018
    Posts:
    28
    I need this! I can't seem to get it to work. I've tried override controller but since there isn't an actual clip, it doesn't override. Can you give me an example of how I can take a recorded animation clip and reply it? I have all the code to record, I just need to know how to apply the clip to be played back.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    8,471
    I'm not suggesting using an animation you created at runtime. I have no idea how to do that.

    I am suggesting if you write down a series of positions, rotations, scales, and whatever other parameters you are interested in, then you can always just "play them back" into new GameObjects, mimicking the original visuals.

    This is the simple explanation, used in lots of racing games to create a "ghost car" of your previous or your best run:

    https://answers.unity.com/questions/227657/record-ghost.html
     
  6. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,479
    Would be best to save out your own format, could either be something like json, or if its a lot of data could make your own binary file type. Once you have it serialized you can just write it with the basic file IO functions to the persistentDataPath
     
unityunity