Same animation to different assets.

Simple situation, seems that not-so-simple solution:

I have several cubes in a scene. All of them should be “pushable” this is, the user can click on them and a “move backwards and then goes back to the initial position” animation should play.

I have an animation clip, made using an empty parent gameObject which moves them in the way I want, but it seems I can’t find a way (if it exist) to make the animation play in the different cubes separately. (I’ve also tried making the animation for one cube, then using on the others, and nothing).

There’s an empty GameObject, parent to all the cubes, which has the animation clip, and a script which is in charge of saying animationVariable.Play(“PushBack”). The script is linked too to each button and I’m using an int to know “which button called” in a OnMouseDown function. But when it plays, all the cubes move altogether.
I’ve also tried to create an animation using one of the cubes, but of course, if I try to play it with other cube, first the cube move to the original cube position, then the animation plays.

Any idea on how to fix it? I am missing something?

Gonna answer myself, as I finally found out how this works. I’ve seen several answers touching this topic, but none of them explaining why it works, so I hope this to be informative.

Making an animation over a model creates a transformation on that model; for instance, if the object is in (10,10,10) (Let’s call it p1), the animation makes the model move to (0,0,0) (Let’s call it p2). This also applies to scales.

Ok.

So, let’s say I have an object in p3(-10,0,10), and I want to play the animation. The object will start in p3, the animation will start placing the object in p1, moving it to p2 and then the object will be placed again in p3.
This sucks if you have several objects and want to use the same animation on all of them, as this animation coordinates are based on the “general” scene coordinates.

Meet the parents.
You got your animation “move from p1 to p2”, and the object in p3. But you want the animation to take place from p3, and not from p1.
So, you create an empty gameObject, place it in p3, and make your object a child of this parent. Now the animation will run as expected.
What happened?
Making the object a child of the parent will “reset” the child’s coordinates to the position of the parent. You can be in p256(80.000,80.000,80.00), create a parent, put the object with the animation, and for that object, the origin of coordinates will be p256.

So, if you have 300 buttons in a scene and want that each button plays the same animation, all you need to do is place 300 parents (One for each button) in the coordinates where the buttons were placed. Then, put each button in (0,0,0), and you are good to go.

Then there’s a weird thing about scales multiplying, but I haven’t touch it too much.