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

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 :frowning:

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.

This is the code:

	void AddCurves() {
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalPosition.x", posX);
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalPosition.y", posY);
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalPosition.z", posZ);
		
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.x", rotX);
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.y", rotY);
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.z", rotZ);	
		clip.SetCurve(relativePath, typeof(Transform), "m_LocalRotation.w", rotW);
	}

Tried with “localPosition.x”, and I know that if I leave the relative path blank, it just attaches the curve to the parent.

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. :slight_smile:

2 Likes

This was super helpful, thanks for posting your findings!

Cheers,
Eric

1 Like

Hey!

I have an issue with the path.

1289405--58905--$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?

1 Like

@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.

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

This still doesn’t seem to work. Has anyone had any success using the relativePath parameter of the SetCurve method?

Very old thread but it came up in Google. Here is some code I use to find the relative path between two transforms.

    string GetRelativePath(Transform root, Transform tr)
    {
        List<string> pths = new List<string>();
        Transform t = tr;
        while (t != root && t != t.root)
        {
            pths.Add(t.name);
            t = t.parent;
        }

        pths.Add(root.name);
        pths.Reverse();
        return string.Join("/", pths);
    }
2 Likes

Complete it with this maybe [Solved] Animation SetCurve anchoredPosition problem

I wish there was a clear and concise doc of the path system.

Can I reference an array element as a property? Some people online seem to mention it but the unity editor doesn’t allow it.

Can I specify which component I’m targeting in the case of two components of the same type?

Which component name is it using, the real one or the addComponentMenu one?

Is it possible to implement the magic used in MeshRenderer to animate materialpropertyblocks?

The animation system is a documentation black holes.

1 Like

AnimationUtility.CalculateTransformPath: Unity - Scripting API: AnimationUtility.CalculateTransformPath

1 Like