- Home /
Animation.AddClip and Playing the Clip
In the following, I'm attempting to create a Clip and play it. I'm successfully instantiating the animation object (anim). I verified that "openClip" is not null. However, when I execute "anim.Play("openScreen")" for the clip, the clip does not play. I verified the return value, which is TRUE. That is, Unity thinks it played the clip. The model has a single baked animation "Scene", which is from frames 1 through 89. Scene will eventually have other clips.
private Animation anim;
private AnimationClip openClip;
public override void OnStart(PartModule.StartState state)
{
anim = part.FindModelAnimators("Scene")[0];
openClip = new AnimationClip();
anim.AddClip(openClip, "openScreen", 1, 89, false);
anim.Play("openScreen");
}
So:
1) what is incorrect in my method of creating and playing clips in the script?
2) can I attach an AnimationEvent, in a script, to a clip I define in the Unity Editor versus doing it in the compiled script?
Bonus question: How can I play a clip backwards? That is, is this legal: anim.AddClip(closeClip, "closeScreen", 89, 1, false); note that the Start frame is greater than the End frame.
Note: I'm not using the Editor Scripting Tool; I'm compiling in C# as a DLL
I displayed the clip length (openClip.length); it showed a length of 1. However, the clip is really 3 seconds long.
Answer by TheMave · Feb 07, 2015 at 04:10 PM
I can't get proper results with AddClip either (wrong/shortened clips result). Only when (manually -aargh) defining the animations in the inspector of the fbx importer.
The simple bonus question, I can answer though: specify negative speed to play a clip backwards.
Your answer
Follow this Question
Related Questions
Play on awake corrupt timeline behavior 2 Answers
Problem while editing animation clips on timeline 0 Answers
how does the animation window work in unity 5 2 Answers
Is there a way to access the current animation clip being edited through a script? 1 Answer
Is it possible to change the size of text in the animator window? 1 Answer