Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Help! I don't get it - AnimationClip.SetCurve "relativePath"

Discussion in 'Scripting' started by lockbox, Jan 28, 2013.

  1. lockbox

    lockbox

    Joined:
    Feb 10, 2012
    Posts:
    519
    I've been trying to solve this problem for about 5 hours. Can't find anything in forum/answers and the documentation isn't helping me at all. (docs) I've been trying all kinds of stuff to no avail :(

    I'm trying to creating a local animation, I have all the right data, what I don't understand, is what exactly I'm suppose to put in relativepath to get the position/rotation data on my Character object instead of on the CharacterEmpty.

    $animation panel.jpg

    This is the code:

    Code (csharp):
    1.     void AddCurves() {
    2.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalPosition.x", posX);
    3.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalPosition.y", posY);
    4.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalPosition.z", posZ);
    5.        
    6.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.x", rotX);
    7.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.y", rotY);
    8.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.z", rotZ); 
    9.         clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.w", rotW);
    10.     }
    Tried with "localPosition.x", and I know that if I leave the relative path blank, it just attaches the curve to the parent.
     
  2. lockbox

    lockbox

    Joined:
    Feb 10, 2012
    Posts:
    519
    So 14 hours later I have the answer to my own question, which I'll share for others in a similar situation.

    You might think it's CharacterEmpty/Character. When then doc's refer to a "path" and given the example, you would think that's you're going to come up with a path that looks like that...

    And you'd be wrong. Just like I was. The correct answer is that the relative path is "Character".

    If I attach something else under the empty that isn't called "Character", and open the animation window, it's going to present the "Clean Up Leftover Curves Button." And if I click on that, it will show the curves that were added under the relative path "Character", which it now thinks should be deleted. There are no curves associated with the object I replaced it with, so it doesn't move when I press the play button. How to fix this problem? I just renamed the other object "Character" and it doesn't know the difference!

    Hope this helps someone. :)
     
    Genso_0 likes this.
  3. eric_kog

    eric_kog

    Joined:
    Mar 6, 2013
    Posts:
    11
    This was super helpful, thanks for posting your findings!

    Cheers,
    Eric
     
  4. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Hey!

    I have an issue with the path.

    $ainmation.jpg

    As you can see, my path should be "Lhand/Armature/Root/Bone1".

    But it doesn't work....

    I have other curves that use just "Lhand" and they do work.

    Any ideas?
     
  5. slippdouglas

    slippdouglas

    Joined:
    Feb 11, 2013
    Posts:
    23
    @dorpeleg: Have you tried “Lhand.Armature.Root.Bone1”?

    I have a suspicion that when the Unity Tech devs wrote “path” they meant to write “key path”. The object hierarchy isn't a filesystem.
     
    Last edited: Jan 16, 2014
  6. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    the path is like a file system for sure.
    because if i do Lhand/Armature it will work
    I think its a bug when u try to go too deep

    this works same as transform.find which also uses a "file system" structure
     
  7. DeanNorth

    DeanNorth

    Joined:
    May 15, 2015
    Posts:
    4
    This still doesn't seem to work. Has anyone had any success using the relativePath parameter of the SetCurve method?
     
  8. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,012
    Very old thread but it came up in Google. Here is some code I use to find the relative path between two transforms.


    Code (CSharp):
    1.     string GetRelativePath(Transform root, Transform tr)
    2.     {
    3.         List<string> pths = new List<string>();
    4.         Transform t = tr;
    5.         while (t != root && t != t.root)
    6.         {
    7.             pths.Add(t.name);
    8.             t = t.parent;
    9.         }
    10.  
    11.         pths.Add(root.name);
    12.         pths.Reverse();
    13.         return string.Join("/", pths);
    14.     }
     
    owen_proto and Genso_0 like this.