Available AnimationStates not updating?

I’m trying to build a list of animations on a gameobject so I can present it as a dropdown in a tool. The code works, but if I add animations, the list of animations I get back from the Animation component doesn’t update until after I play or restart the editor.

Here’s how I’m collecting the animations:

		List<AnimationState> animations = new List<AnimationState>();

		if (gameObject != null)
			if (gameObject.animation != null)
				foreach (AnimationState anim in gameObject.animation)
					if (anim.clip != null)
						animations.Add(anim);

Again, it works, but the list doesn’t update as I add animations.

Am I doing something wrong? Is there a way to force an update? Is this a bug?

I’m experiencing the same problem - the list of animations is not updated after a animation was added or removed.
Calling GetClipCount() returns the correct new size, but iterating the AnimationState instances uses the old size.
Looks like a cleanup/update issue, IMHO that’s a bug.

Using Unity3 here. Did not test in 2.6.

PS: Thanks for the play workaround - didn’t know that.

This problem has been logged as a bug.

So um, this hasn’t been fixed yet? I am still having this problem and we are in 2013…

hmm seems like this bug is still in 4.3.4f1

This is still a bug in Unity 2017.3.1f1