- Home /
Play animation in the editor?
I'm working on support for animation of mouth movements. The animator needs to be able to watch the mouth movement animation while listening to the audio sample. How can I support this in the Unity editor? It's easy to program a GUI button to play the audio sample, but how do I play the animation in the editor?
Here are some approaches I've considered and couldn't make work:
Use the playback feature of the Animation Inspector. (Sadly I have no idea how to do this: there seems to be no script interface for this.)
Use
AnimationUtility.SetAnimationEvents
to place an event at the start of the animation that calls a function that plays the audio. (But the event does not get called when playing the animation from the inspector.)
and here are some approaches I'm still considering:
Make an
ExecuteInEditMode
script. Look atEditorApplication.timeSinceStartup
in itsUpdate
method. CallAnimationUtility.GetAllCurves
to get the list of curves for the animation of interest. For each curve, callAnimationCurve.Evaluate
to get the value for the current time. Apply this value to the appropriate transform. (Yuck!)Abandon the idea of trying to play back the animation in the editor. Instead, set some variables, set
EditorApplication.isPlaying = true
, and arrange to play the animation and the sample from the game. (Slow to start, and causes an inconvenient window switch in the editor.)Instead of editing the lip-syncing animation in edit mode, edit it in play mode using a special mode of the game. In play mode it's easy to play the animation synchronized with the audio. (This works. However, edits you make during play are lost when you exit unless you remember to "Apply" them to a prefab. Perhaps I could use
EditorUtility.ReplacePrefab
to save changes?)
What's the best approach? Is there a better idea that I've missed?
(A similar question, but no answers: Play animations in editor.)
I was just running into this same issue today. Would REALLY like to preview a) the raw animation from FBX and b) the individual 'splits' I create from them
If you just want to preview the animations, then you can play them in the animation inspector. (But if you want to do something more complicated that needs scripting, then I sympathize.)
Answer by Paulius-Liekis · Mar 21, 2011 at 09:00 AM
Your first idea is closest to the answer, but a little bit overcomplicated. Just set appropriate time on animation state(s) and call Animation.Sample.
I tried that first. Animation.Sample
has no effect in edit mode for me.
Really? I tried it in AssetPostprocessor and definetelly works there. If Animation.Sample doesn't work, then you should submit a bug with $$anonymous$$i repro (and post case number here).
This only works for me if I add a call to Animation.Play() after setting the time on the AnimationState (before caling Animation.Sample())
Answer by neonfire · Jul 12, 2011 at 02:32 PM
It seems that animation.sample doesn't work, but if you call gameObject.SampleAnimation(clip, time) then it works fine in editor mode.
Answer by breakeren · Dec 20, 2011 at 11:28 PM
use AnimationUtility.StartAnimationMode() to emitate the mode of the AnimationWindow
Your answer
Follow this Question
Related Questions
Get a list of clips in an animation component from script. 1 Answer
Issue with a Mecanim motion reference in synchronized layers 0 Answers
Animation Editor Window – Get Active Clip Info 1 Answer
UnityEditor script, retrieve all the AnimatorControllers 1 Answer
Creating Editor 2D Animation Preview 2 Answers