Animation won't play for Instantiated objects...

Hello all.
I’m trying to animate a instantiated object in my scene, but the animation won’t play. In the object prefab I’ve set “Play Automatically” to false - I’ve heard somewhere that has to be done?

Well, anyways - here’s my code:

Instantiate (playerCharacter, initPos, Quaternion.identity);
playerCharacter.animation.CrossFade ("walk");

The “walk” animation won’t apply at all to the character… What am I doing wrong?

Edit: Does this has something to do with that the Instantiated character is named “xxxx (Clone)”?

Yes, sort of. The clone isn’t the same as playerCharacter so you need to make a variable to reference the new one:

var character:GameObject = Instantiate (playerCharacter, initPos, Quaternion.identity);
character.animation.CrossFade("walk");

The tag will stay the same, so you can always use that to get a reference in other scripts.

I also have a similar issue:
When i manually create the player in the scene, the animation plays perfectly. But when it is instantiated through script a similar animation is played; I mean a sort of a variant, like it rotates the way it should but its position is somehow fixed

Wow, didnt realize I was replying to something that was 10 years ago