Animation does not play in relative position, even with parenting

I created a simple bounce animation using Unity's animation editor. I learned that you have to create an empty game object as a container/parent if you want the animation to play at the current position of the object, so I did and put the player object inside this empty game object. Then I created the animation on the player object itself.

A script, also on the player object (not the empty game object!), triggers the animation when you reach a certain coordinate.

To my frustration, when I play the animation, it plays it at the original coordinates of the player object, and NOT at the location it currently is at.

Have I forgot something else? Am I missing something?

To recap: I have an empty game object as a parent. The animation (and scripts, rigid body, collider, etc...) are all located on the player object INSIDE the empty game object.

Help would be much appreciated. Thanks.

Okay, after struggling for another day I seem to have found the solution.

The solution is that I need to animate the empty PARENT object, the container, and NOT the game object inside it! Since my script is still attached to the object inside the empty parent, I need to call the animation on the parent like this:

currentTransform.parent.animation.Play("BounceTest4");

I don't think I have ever seen this in a tutorial, but apparently it works. I wish the documentation would be more clear about this, because the bald patch on my head is definitely growing.

I'm guessing: The original animation was in world space. When you parented it, it offset that to appear in the same place, offset from the parent. Check the values on your animation curve(s) they may be quite different from what you originally authored.

In addition to the previous answers, make sure root transform has no animation curves. If it does, it will play in world space.

do you have the complete script sentence.

currentTransform.parent.animation.Play(“BounceTest4”);

im having the same problem with just getting an enemy to have a walking animation when it comes towards me. any help??