- Home /
How to edit read only animations
Hello, I have been looking through numerous solutions to this problem and im not sure they meet my situation. I have an FBX blender model that has read only animations. I need to add keyframes/events to this animation to be able to call a function. My animations are contained within my model though, so if I try to duplicate the animation like other posts have said, it is not possible. I've heard that if you put the model in the scene, then make a prefab of that model, then it would work, but I already have a prefab based off this model... Does anyone have any experience with this situation? I have looked at this post already:
http://answers.unity3d.com/questions/187907/how-to-add-keyframes-on-imported-read-only-animati.html
if someone could offer a more detailed solution they used that would be awesome. Thanks,
Answer by blorange · Sep 18, 2014 at 07:59 PM
I think I just worked this one out..
When Unity imports the FBX, the animation clip by default (at least on my Unity) is given a name like 'Anim|Cube'. You have to rename this in the import settings for the object, removing the | characters. Then after clicking apply, you can click on your clip in the project browser, press Ctrl-D and it should give you a copy outside the object.
Hope it works,
devDoug
Answer by mchts · Apr 23, 2016 at 06:58 PM
I'm also using read-only animations. And I've also tried duplicating my animations and edit them manually. But it's troublesome. So i add my events to my animations at runtime once in Start(). For instance this is an event which calls a function with a float parameter:
AnimationEvent animationEvent = new AnimationEvent();
animationEvent.functionName = "your method name to be called"
animationEvent.floatParameter = "single type parameter you want to pass"
animationEvent.time = "time when to trigger event"
Animation["state you wish to add event"].clip.AddEvent(animationEvent);
Then define your method in your script and it will be fired off as you described.
Good solution... but "Animation["state you wish to add event"].clip.AddEvent(animationEvent);" not work for me.
I modify your code:
void AddEvent(int $$anonymous$$yClip, float time, string functionName, float floatParameter) {
anim = GetComponent();
AnimationEvent animationEvent = new AnimationEvent();
animationEvent.functionName = functionName;
animationEvent.floatParameter = floatParameter;
animationEvent.time = time;
AnimationClip clip = anim.runtimeAnimatorController.animationClips[$$anonymous$$yClip];
clip.AddEvent(animationEvent); }
Thanks to all. This definitely set me on the right track. Adding events at runtime fixed it for me.
Answer by WILEz1975 · Dec 02, 2017 at 07:36 AM
But beware, in the presence of multiple objects with the same animation, the event is added several times because the animation is always one for all the objects. You need to add a static variable that specifies that the event should only be added once.
public static bool EventsAdded;
void Start() {
if (!EventsAdded)
{
AddEvent(13, 0.3f, "TriggerActive", 0); //my events
AddEvent(13, 0.5f, "ShotFire", 0);
AddEvent(14, 0.5f, "DeleteObject", 0);
.....
EventsAdded = true;
}
This should only be done if there are more objects with that animation.
Or... you can add events following this: link
Your answer
Follow this Question
Related Questions
Animation events are still executing after transitions 1 Answer
changing a specific keyframe value 0 Answers
Manually Animating Bones then blending with existing animations or saving importing as fbx 3 Answers
2D Animation does not start 1 Answer
Unity Import automatically adds unnecessary Keyframes 2 Answers