- Home /
Copying Animation Clips from Imported FBX
I've been reading several posts on this forum that explain how it isn't possible to edit animation clips on a model imported as an FBX (in my case, from Blender), because it's read-only, and that it's necessary to duplicate the animation clip first, and then copy the curves across with an editor script (see here: http://answers.unity3d.com/questions/8172/how-to-add-new-curves-or-animation-events-to-an-im.html)
My problem is that while I can indeed duplicate the clip in question, it insists on placing itself in the Hierarchy folder containing the imported model, but refuses to sit within the imported model. OK, you say - not surprising, because it too is Read Only. Well, the problem I have is that unless it is part of this model, Unity fails to find it if I try to ask the model to play it. I cannot view the new copy in the Animation window either, because it is not part of an object.
Interestingly, I found that at runtime I can call AddClip to add the copied clip to the model, and this actually animates - which is cool, but I still cannot edit the copy in the Animation window because Unity is currently in Play mode. As soon as I go back out of Play mode, I'm back to square one.
I cannot for the life of me find the answer anywhere on the internet, and I'm tearing my hair out now. Can anyone put me out my misery please? I am using Unity 3.5 (basic). I wonder perhaps if something has changed since the article I reference above was written?
I have thought about trying to duplicate all the clips on model-import, but haven't had any success. And, frankly, I can't believe it's really that ugly to achieve what I need here? I've also tried duplicating the imported (FBX) model, with cmd(ctrl)-D, but its animation pane is greyed-out like the original, preventing any changes, so this is a dead-end too (all it's done is duplicate the FBX file on disk - whereas what I hoped for was an editable duplication of the model and its animation data within Unity)
I must have missed something really obvious here? All I want to do is trigger a script to occur at a certain stage of the animation - that is all.
Thanks in advance. Borrus
Update: Just found this: http://answers.unity3d.com/questions/187907/how-to-add-keyframes-on-imported-read-only-animati.html. This suggests I should be able to drag my newly-copied animation clip onto a prefab of my model and edit the clip in the animation window. Unfortunately this doesn't work for me either - it's still read-only. And yes, I have copied the curves over to it.
Hmm. The prefab for my model is a placeholder game object which references the $$anonymous$$odel Object from the FBX and instantiates it at runtime. This is as recommended elsewhere on this site, so that re-importing the FBX does not result in having to set everything up again in Unity every time.
Perhaps the simple truth is that this approach is incompatible with the need to modify the model's animation curves? I'd love to know how other people have things set up - I'm in a right ol' mess here...
O$$anonymous$$, I believe I have a solution to this, which I'll describe in case anyone else has similar problems. Following my previous comment, I realised that if I simply drag my FBX-imported model onto the scene, I could then finally edit my animation clips. Woo... Also, if I then made it a prefab, I could still do so. This lead me to look at writing an import (i.e. Editor) script that instantiates each new FBX (adding it to the scene), makes a prefab out of it and then destroys the instantiated object:
using UnityEngine; using UnityEditor;
public class Import$$anonymous$$odel : AssetPostprocessor { public void OnPostprocess$$anonymous$$odel(GameObject root) { $$anonymous$$odelImporter modelImporter = ($$anonymous$$odelImporter) assetImporter;
// Instantiate object in scene
GameObject inst = (GameObject)GameObject.Instantiate(root, Vector3.zero, Quaternion.identity);
// Create prefab for it
Object prefab = EditorUtility.CreateEmptyPrefab("Assets/$$anonymous$$odels/" + root.name + ".prefab");
// Replace the empty prefab with the newly instantiated model object
EditorUtility.ReplacePrefab(root, prefab, ReplacePrefabOptions.ConnectToPrefab);
// Destroy the object we added to the scene
GameObject.DestroyImmediate(inst);
}
}
(apologies for formatting issues - I think this is a line-ending issue with this site)
Once the models are imported via this script, they can then be referenced by the 'empty' that instantiates them at runtime (so that there is no work setting things up again when the model is re-imported).
This just leaves the animation clips. The solution here is to duplicate them - but now, they can be added to this new prefab generated by the editor script above, and they are also then editable. Solution! I'm going to add that to the script above, but haven't got that far yet. I'm sure it's achievable though.
So it looks like I answered my own question here. If anyone's got a better solution, please do speak up though :)
Cheers Borrus
Update: O$$anonymous$$, Seems the solution I posted above does not work, so converting it back to a comment, rather than an answer.
First, it is not possible to duplicate animation clips in the editor, it transpires. Second, even if it were possible, how would you then manage the conflict between inco$$anonymous$$g changes to the imported clips and changes made within Unity?
I came up with a solution where I manually create copies of the FBX's clips, and integrate Rune's curve-copying script so this happens for each model during import. This worked wonderfully. If you then drag the copy of the model to the scene, you can edit the curves of the copied clip. However, if like me you have a prefab object which references the model object, in order to avoid having to recreate the GameObject and all its components every time you re-import, and this is what you drag to the scene (and not the copied model), you are stuck: if you click on a model form the Project pane (not the Hierarchy pane) and view its animations, you still cannot edit copied clips, even though they are read/write: the record/play buttons are simply greyed-out :/
I do realise this is probably getting very difficult to follow due to complexity. Perhaps I should call it a day updating my findings here, unless anyone out there is finding it useful.
Answer by demented_hedgehog · Jan 25, 2015 at 09:41 PM
Select the animation in the fbx and press Ctrl-D... that does what I thik you want? http://forum.unity3d.com/threads/extract-1-animation-from-an-fbx.164509/
You just saved my life also. I just cannot wrap my head around that you cannot ctrl+c / ctrl+v it...