Search Unity

Why is altering AnimationClip paths in a custom editor so awkward and sluggish?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Xelnath, Mar 21, 2015.

  1. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    In order to change the animation path of a few curves, I have to do the following:

    Code (csharp):
    1.  
    2.                
    3.                 for (int i = 0; i < curves.Count; i++) {
    4.                     EditorCurveBinding binding = (EditorCurveBinding)curves[i];
    5.                     AnimationCurve curve = AnimationUtility.GetEditorCurve(animationClip, binding);
    6.                     ObjectReferenceKeyframe[] objectReferenceCurve = null;
    7.  
    8.                     if (path == oldPath) {
    9.                        
    10.                         if (curve != null) {
    11.                             AnimationUtility.SetEditorCurve(animationClip, binding, null);
    12.                         } else {
    13.                             objectReferenceCurve = AnimationUtility.GetObjectReferenceCurve(animationClip, binding);
    14.                             AnimationUtility.SetObjectReferenceCurve(animationClip, binding, null);
    15.                         }
    16.  
    17.                         binding.path = newPath;
    18.  
    19.                         if (curve != null) {
    20.                             AnimationUtility.SetEditorCurve(animationClip, binding, curve);
    21.                         } else {
    22.                             AnimationUtility.SetObjectReferenceCurve(animationClip, binding, objectReferenceCurve);
    23.                         }
    24.                     }
    25.                 }
    26.  
    It seems utterly ridiculous that I cannot simply do

    Code (csharp):
    1.  
    2. binding.path = newPath
    3.  
    I am writing a tool that automates some animation hierarchy problems with importing animations... and it is actually faster for me to parse the .prefab file, perform a text replace, then reimport the prefab than it is to change the binding.path inside the editor.

    Help me, Unity Jedis!
     
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Hey there,

    Are you editing a ton of animations when you run this script or is it sluggish even with one animation?
     
  3. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Hey BMayne,

    It is sluggish, even with one animation. When there's 10, it goes from 5-6 seconds of unresponsiveness to 30-40.

    I can help with repro steps here if you would like them.
     
  4. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Also - I've temporarily given up on this method of editing. I am now copying out every curve into a new animation from scratch and saving it to a new .anim file, then mass deleting the animations and renaming them afterwards.

    The result is many hundreds of times faster and doesn't result in workflow disruption.
     
  5. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    I was going to say if it's just when you edit a ton of assets It might just be that you are missing

    Code (CSharp):
    1.       AssetDatabase.StartAssetEditing();
    2.  
    3.       //Edit your assets
    4.  
    5.       AssetDatabase.StopAssetEditing();
    Ass
     
  6. Xelnath

    Xelnath

    Joined:
    Jan 31, 2015
    Posts:
    402
    Trying this now...

    Edit: That helped significantly! Still slow, but now all 10 clips take 10 seconds, instead of each one taking 10 seconds.
     
    BMayne likes this.