Child Legacy animation doesn't play

For a 2d game. I have a block that has a child object which I’d like to animate whenever a certain action occurs. I set up the animation in the Animation window, and I can see it working properly. I hit play and I can see it running over and over again in Preview mode. This animation only happens per run to the block, so I don’t need all that unnecessary transition stuff. I make the animation Legacy, and when I try to fire the animate call I see nothing. I get no errors. Here’s the code trying to run the animation:


            try {
                Animation a = this.gameObject.transform.GetChild(0).GetComponent<Animation>();
                if (a != null) {
                    a.Play("falling_dots", PlayMode.StopAll);                    
                    Debug.Log("Playing falling_dots");
            } catch (UnityException ue) {

The image shows my object’s hierarchy. At the top floating_block_animated is the parent object and falling_dots is the child. The Inspector is showing the child

Lastly, if there’s a better way to do this I’m open to suggestions.

I was having a similar problem, very frustrating. I found that calling a different overload with explicit playmode defined in Animation.Play/CrossFade made it work.

So instead of just anim.Play(“name”) try using

anim.Play("name", PlayMode.StopAll);


anim.CrossFade("name", 0.5f, PlayMode.StopAll);