Using animator recording, saving out to file

Hi,

I am trying to record the animator to a file so it can be played back in a seperate program. I’ve found you can’t set states or clip times and speeds specifically in mecanim (or can you, might not of found the solution for that yet?) I have seen there is a StartRecording() and StartPlayback() functions in mecanim, but they don’t seem to be able to save out to a file, just stored in memory.

Any help would be great, thanks.

Mechanim isn’t an animation editing program, it’s just a graphical node based way to put animations together to make life a easier on programmers. I’m not sure why you would want to save mechanim animations. You already have all the animation files, just put them together in an animating package

I think I wasn’t clear in my intentions, the other program will still be a unity program using similar code, a kind of playback machine to show recorded sessions. I just need a good way to save out the current state of the animator and set it back when you want a view a recording of it on a different computer on the same or similar app.

I’m sorry I don’t know what to tell you, whatever the solution is it won’t be easy. I’d guess you’d need to record all the states of the animator with GetCurrentAnimatorStateInfo and get the transition info (GetAnimatorTransitionInfo) if(IsInTransition) And maybe add all of these to an array/list and just have a script go by and change what state to play based on their length, which you’ll probably need a second array/list to pull info from

I’m sorry I don’t have much for you, I wish you all the luck in the world though :smile:

For those wondering, I’ve managed to record an animator through a bit of a hacky method, until Unity implement more direct state control.

I did it by implementing a state machine that has an instant transition boolean and a state integer. Setting the state integer will cause the animator to progress through it’s states with every state being linked to a specific number (all the transitions use that state as their condition, for example 0 is Idle state, but if state is greater than 0 and less that 2 then the state is Walking).

Using this system I can record the integer and if I need to go instantly to a state without going through the typical order, setting instant transition bool will make the animator transition straight to the state you have defined in the integer (the Any State node is linked to every state with the condition being the instant transition bool == true and the states number).

The only thing you have to do is every update you check if the instant transition bool has been set to true, and if it has set it back to false, else it will keep trying to transition to that state you’re point at. Pausing is easy, just set animator speed to zero.

Also when playing back, you have to do it over several frames, and the transitions to state aren’t really instant. I record the normalised time of the current state and if it is in transition. When playing back I keep checking to see if the state is the correct state from the recorded data (using the IsName on current state info) and if the animator is no longer transitioning. Once those are are both true, I can successfully set the normalised time with the ForceNormalizedTime function of the animator. I can then pause, or just continue playing. (This is mainly for scrubbing a timeline, you could just go from the beginning setting the state Integer right if you want linear playback).

Just thought I’d post my findings for anyone else, as the animator can be a bit frustrating when it comes to recording it.