- Home /
Deleting animation curve with editor script
I duplicated animation. I can delete it using animation editor, but i need to delete a lot of animations, so i need a script. I have this one, but it doesn't work((( Code:
using UnityEngine; using UnityEditor; using System;
public class FixAnimation : ScriptableObject { [MenuItem("Custom/FixAnimation")] static void ListChildTransforms() {
GameObject go = Selection.activeGameObject;
string parent_name = go.name;
AnimationClip anim=go.animation["jumpc"].clip;
//Hip
anim.SetCurve("Player/Armature/Master/Ass/Hip", typeof(Transform), "m_localPosition.x", null);
anim.SetCurve("Player/Armature/Master/Ass/Hip", typeof(Transform), "m_localPosition.y", null);
anim.SetCurve("Player/Armature/Master/Ass/Hip", typeof(Transform), "m_localPosition.z", null);
}
}
It can be compiled, but it doesnt delete animation curves. Help me, please!!!!!!
Flagging for close, as Igor's answer says it's fixed, and he hasn't been back since June.
Answer by runevision · Jun 02, 2010 at 11:18 AM
First of all, you are using wrong property names.
Look at the documentation:
http://unity3d.com/support/documentation/ScriptReference/AnimationClip.SetCurve.html
It states that you can use localPosition.x
, not m_localPosition.x
. Note that m_LocalPosition.x
is undocumented but should also work (no guarantee for future versions); however, notice the upper case L.
If you fix the property names themselves, and it still doesn't do anything, check that your path names are correct.
The path "Player/Armature/Master/Ass/Hip" will look for a child called "Player" and go down from there, so this should work if the Animation component is on the parent of "Player", but not if the Animation component is on the "Player" GameObject itself.
Thanks for Reply, but i have already seen documentation, many times, I tried localPosition.x, m_localPosition.x, LocalPosition.x, m_LocalPosition.x, simple "localPosition" and "LocalPosition" I have already used "Armature/$$anonymous$$aster/Ass/Hip" path, "$$anonymous$$aster/Ass/Hip path", "/Armature/$$anonymous$$aster/Ass/Hip"
Nothing help me. So. Can you give an editor script, that works on your animation clip, that deletes your one curve. It must be not a big work, but can help me and other people, because it is useful for optimization of animation.
Here is a "prefab code", try it on your animation, please!!! And sorry for my persistence
using UnityEngine; using UnityEditor; using System;
public class FixAnimation : ScriptableObject { [$$anonymous$$enuItem("Custom/FixAnimation")] static void ListChildTransforms() {
GameObject go = Selection.activeGameObject;
string parent_name = go.name;
AnimationClip anim=go.animation["name of clip"].clip;
anim.SetCurve("path", typeof(Transform), "localPosition.x", null);
}
}
And I have Debug message: "Cleaning up leaked objects in scene since no game object, component or manager is referencing them AnimationClip has been leaked 6 times. " But I dont understand what actually does it mean.
And this error without "m_" Can't remove individual position animation curve localPosition.x you must remove the entire animation curve with m_LocalPosition.
Thanks, $$anonymous$$r Rune, for help, you are clever and reliable, humanity needs more humans like you. I've done with it. It was a bug, after copying project to another folder and reopening, everything begin work well.
Igor, could you mark Rune's answer as correct then, so other people know that this question is answered.