- Home /
How to change object's hierarchy level in animation?
The Animation View in Unity allows us to make references to objects (their properties, to be exact) with different hierarchy levels, so we can apply one animation to all objects that share certain structure. But what if I created, tested and polished a set of transitions on some object and now I want to nest it somewhere else in its parent (which holds the Animator Component)?
What I expected from the Animation View was an option to change "hierarchy level" of different properties (like changing indent level in some text editors), but I couldn't find anything like that. So, am I doomed to delete all properties and start over again with new references? Or edit the animation's file by myself?
I bet there's simpler and more sane solution to that problem, as it seems to be too obvious not to think about it in the development process of Unity. However, either I cannot phrase the question properly, or people haven't encountered that kind of problem before (or I'm just blind).
TLDR I want to do this:
Before:
After:
How to do it painlessly?
EDIT: If you need that functionality, you can vote for it here: http://feedback.unity3d.com/suggestions/ability-to-edit-object-hierarchy-in-animation-clip
I hope devs will provide it.
Answer by gyd · May 10, 2017 at 07:38 PM
Try This one: GitHub Link
Looks pretty good, why does the link not work?
I think it should replace my ad-hoc version.
Because I add a readme for the script, thanks for feedback. Now it has been fixed. :)
This looks amazing! Unfortunately I can't seem to get it working. Can you explain the steps to set it up please? Thanks
Answer by s-m-k · Mar 20, 2014 at 12:37 AM
UPDATE:
@gyd wrote a more elegant plugin that detects the hierarchy changes automatically:
OLD ANSWER:
Noone? It seems I had to solve that issue by myself.
I've written a simple editor to help fix broken animations. It should be pretty straightforward to use, but if you have some questions or found a bug, don't hesitate to contact me.
Here's the screen:
You can manage relative references by assigning a sample animated object to "Referenced Animator (Root)" (you can use prefabs here), then it will show you broken links (red color). You can then simply drag and drop child objects to the editor.
If you don't want to use any sample object, you can always edit paths manually, but you won't know if your paths are correct.
The code: https://github.com/s-m-k/Unity-Animation-Hierarchy-Editor/blob/master/AnimationHierarchyEditor.cs
Put it in YourProject/Editor folder to make it work, you'll find it in "Window > Animation Hierarchy Editor".
UPDATE: now my code should support sprite animations (and other object reference curves). I hope that it will save your time.
I have created a new version of this editor which allows you to multi-select animations to mass-update multiple animations.
This was super helpful for importing a Spriter object and mass-replacing the references.
I've created a pull request in GitHub.
Tnx! You saved me a lot of time! Though I commented out a part of the code, because I had two references to the same object with different properties (thething : position and thething : rotation) and this part of code prevented me from changing the reference.
void UpdatePath(string oldPath, string newPath)
{
//if (paths[newPath] != null) {
// throw new UnityException("Path " + newPath + " already exists in that animation!");
//}
I guess I'm the only one having difficulty understanding this script. I've been able to drag and drop to fix red broken links, but what does the "change" button do, and what are the numbers (change 1, change 2,...) next to the change button mean? Lastly, what is the replace root for? Looks like it only takes string values. Thanks, I really hope someone can explain this cuz I've been trying to fix my animations for hours and I am not making much progress. :(
From what I understand (I'm not the only contributor now) the "Change" is meant to apply the new path (i.e. actually save to the animation file) and "replace root" changes all paths according to the new root, e.g., if you have Animator component attached to "OldRoot" object and animate "NewRoot/SomeObject1" and "NewRoot/SomeObject2", you can change the root to "NewRoot" and paths will be automatically changed to "SomeObject1" and "SomeObject2".
Answer by Panzermjau · Apr 22, 2016 at 08:16 PM
Awesome script @s-m-k !
I created a simplified variant of it here:
Fixes the problem with rotation getting a keyframe on each frame!
Changes:
Instead of going via Unity's AssetDatabase API it reads the .anim files as raw text and replaces the path within them.
Removed the individual path remapping to new GameObject stuff.
Requires your assets to be serialized as text: Edit / Project Settings / Editor / Asset Serialization / Force Text
Hope people find it useful!
Nice, +1. How unprofessional on Unity's side though, that they still didn't fix that workflow-breaking issue by themselves after 2 years.
Odd problem I had with variant. Seemed the greater the hierarchy, the more time it took to process. Had a 3rd child running for about 15$$anonymous$$utes (very fast PC), didn't bother waiting for a 4th child. Excellent if only not for that problem.
Answer by ofusion · May 12, 2014 at 06:59 AM
Thanks for sharing this useful tool. But I find that broken sprite animation is not listed in the animation hierarchy editor.
$$anonymous$$aybe the sprite animation is root animation? The tool cannot list root afair, but I'll look at it later.
I've checked it and yeah, you're right, AnimationUtility.GetCurveBindings seem to ignore the sprite property :(
I don't know how to fix it at the moment (besides editing the binary file), but maybe there is a way to get also that kind of stuff.
I wonder why the Unity staff didn't implement such utility by themselves, maybe it's time to send a feature request?
EDIT: http://feedback.unity3d.com/suggestions/ability-to-edit-object-hierarchy-in-animation-clip
I've updated my code, so it supports object reference curves (including sprite animations): https://github.com/s-m-k/Unity-Animation-Hierarchy-Editor/blob/master/AnimationHierarchyEditor.cs
Answer by RChrispy · Jul 02, 2014 at 02:28 PM
Seems like this script is not working anymore?`:(
I've just successfully used this tool to edit animation, can you be more specific about your problem?
Thank you, s-m-k! I think this just saved my butt on a tight deadline.