- Home /
Animating meshes in the editor
We are running into a problem in the editor. We are trying to have a character model display in the scene view at a particular frame of animation, so we can position it based on the pose in the middle of an animation. We have tried setting the time in the animation state component. We have done this both manually in the inspector, and in a script triggering off the gizmo update. Neither one seems to work. The scene view always displays our character model in the davinci pose, with a unity matrix list.
How can we get the model in the scene view to display articulated to a frame of animation?
An alternative would be to use the animation editor. However it appears that we can only change the time for a single object in the scene at a time, not multiple characters. Is there a way to animate multiple meshes in the animation editor?
Answer by AngryAnt · Nov 24, 2009 at 05:14 PM
Based on Runes answer, you could use this quick and dirty custom inspector to line it up:
using UnityEngine; using UnityEditor; using System.Collections; using System.Collections.Generic;
[CustomEditor (typeof (Animation))] public class CustomAnimationEditor : Editor { AnimationClip m_SampleClip; float m_SampleTime = 0.0f; List <AnimationClip> m_ClipList; List <string> m_ClipNameList;
public List <AnimationClip> ClipList
{
get
{
if (m_ClipList == null)
{
Animation animation;
animation = target as Animation;
if (animation != null)
{
m_ClipList = new List <AnimationClip> ();
foreach (AnimationState state in animation)
{
m_ClipList.Add (state.clip);
}
}
}
return m_ClipList;
}
}
public List <string> ClipNameList
{
get
{
if (m_ClipNameList == null)
{
List <AnimationClip> clipList;
clipList = ClipList;
if (clipList != null)
{
m_ClipNameList = new List <string> ();
foreach (AnimationClip clip in clipList)
{
m_ClipNameList.Add (clip.name);
}
}
}
return m_ClipNameList;
}
}
public override void OnInspectorGUI ()
{
DrawDefaultInspector ();
Animation animation;
animation = target as Animation;
if (animation == null)
{
return;
}
int clipIndex, newClipIndex;
float newSampleTime;
clipIndex = m_SampleClip == null ? 0 : ClipList.IndexOf (m_SampleClip);
newClipIndex = EditorGUILayout.Popup (clipIndex, ClipNameList.ToArray ());
if (clipIndex != newClipIndex)
{
m_SampleTime = 0.0f;
}
m_SampleClip = ClipList [newClipIndex];
newSampleTime = EditorGUILayout.Slider ("Sample time", m_SampleTime, 0.0f, m_SampleClip.length);
if (m_SampleTime != newSampleTime)
{
animation.gameObject.SampleAnimation (m_SampleClip, newSampleTime);
}
m_SampleTime = newSampleTime;
}
}
Answer by runevision · Nov 24, 2009 at 03:51 PM
To sample an animation in the editor, you can use GameObject.SampleAnimation, which works fine at editor time. You can create a simple editor script that places a menu item in the menu. In the function called by this menu item you can use SampleAnimation to sample an Animation Clip of your choice.
Note that once a certain pose has been sampled at editor time using SampleAnimation, you cannot easily go back to the bind pose (the davinci pose in your case), unless you have made an animation for that pose, such that you can sample that one to go back.
Your answer
Follow this Question
Related Questions
How to make Bones visible in Editor Mode ? 5 Answers
Deleting animation curve with editor script 1 Answer
Can't select function in Animation Event 9 Answers
Editing Animations crashes Unity 1 Answer