Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ben Blaut · Feb 25, 2013 at 09:45 PM · animationanimationclipanimationcurve

How can I reassign animation curves to play on a child object (instead of through parent)?

I currently have an imported FBX with an animation that controls its children. I have a selection script so that if I click on any part of the model and drag the mouse, the animation will play. In this instance, it's a model of a throttle with two levers as children. I want to make it so that if I click on a lever, it will only move that specific lever instead of both. So far, I have a script that attaches a new animation to each child that originally had curves on it, and also attaches an animation clip with curves. The problem is, these curves aren't correct and I'm not sure where they're coming from. Here's what I have:

 var curvePaths : List.<String> = new List.<String>();
 var curveTypes : List.<System.Type> = new List.<System.Type>();
 var curvePropertyNames : List.<String> = new List.<String>();
 var curves : AnimationClipCurveData[];
 var testClip : AnimationClip;
 var sceneObjects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];

 for (var sceneObject in sceneObjects) {
   if (sceneObject.animation != null) {
     if (sceneObject.animation.clip != null) {
       var i = 0;
       testClip = sceneObject.animation.GetClip("Take 001");
       curves = AnimationUtility.GetAllCurves(sceneObject.animation.clip);
         for (var curve in curves) {
           curvePaths.Add(curve.path);
           curveTypes.Add(curve.type);
           curvePropertyNames.Add(curve.propertyName);

           for (var curvePath in curvePaths) {
             var newAnimation : Animation;
             var newClip : AnimationClip = new AnimationClip();
             var realObject = GameObject.Find(curvePath);

             if (realObject.animation == null) {
               newAnimation = realObject.AddComponent(Animation);
             }

             newClip.SetCurve("", curveTypes[i], curvePropertyNames[i], curve.curve);
             realObject.animation.AddClip(newClip, "Take 001");
         }
         i++;
       }
       DestroyImmediate(sceneObject.animation);
     }
   }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Ben Blaut · Apr 26, 2013 at 05:58 PM

I solved this problem by creating new animations for each unique child that was animated and re-assigning the curves to its respective animation. I then attached these clips to the parent object.

 var curveDataArray : AnimationClipCurveData[];
 var uniquePaths : ArrayList = new ArrayList();
 var parentObject : GameObject;

 // If there is an animation on the object with a clip
 if (obj.animation != null) {
   if (obj.animation.clip != null) {
     // Get all the curves in the clip
     curveDataArray = AnimationUtility.GetAllCurves(obj.animation.clip);

     // For each curve
     for (var curveData : AnimationClipCurveData in curveDataArray) {
       // Check if the object the curve applies to has already been seen
       if (!uniquePaths.Contains(curveData.path)) {
         var newClip : AnimationClip = new AnimationClip();
         var assetPath : String;

         // If not, add it to an array to denote that it has been seen
         uniquePaths.Add(curveData.path);

         // Add the created clip to the asset database
         assetPath = "Assets/" + curveData.path + ".anim";
         AssetDatabase.CreateAsset(newClip, assetPath);
         AssetDatabase.SaveAssets();

         // Put the clip on the object
         obj.animation.AddClip(newClip, curveData.path);
       }
     }
   }
 }

 // For each curve
 for (var curveData : AnimationClipCurveData in curveDataArray) {
   // Only do this for each unique curve object
   if (uniquePaths.Contains(curveData.path)) {
     var curveClip : AnimationClip;

     // Get the empty clip that was added to the object
     curveClip = obj.animation.GetClip(curveData.path);

     // Set the curves in that clip
     AnimationUtility.SetEditorCurve(curveClip, curveData.path, curveData.type, curveData.propertyName,    curveData.curve);
   }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

animationClip affected transforms 0 Answers

Setting keys in Animation Editor through Editor code 0 Answers

SetCurve not working for me. 1 Answer

AnimationCurve for ScriptableObject 0 Answers

What is the proper use of AddClip and SetCurve? weird Quaternion error 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges