Getting active controller animation name

I know how to do this with the legacy animation component, but I’m not entirely certain how I’m suppose to get the name of whatever animation is playing if I’m using the newer animator component. I’ve been told that apparently I have to get information from the AnimatorStateInfo, but no information from this structure seems to be helpful. Exactly what am I suppose to do if I want code to tell the difference between a walking animation or an idle animation?

I believe the point of using an Animator is that it becomes the interface to the animation subsystem, so that sort of implies you don’t care what the animations are. Instead you care what the states are, and that way your code won’t break if you forget and change the name of an animation in the future.

That said, there is this method, which might get you something like what you’re looking for:

Be careful though because the more you tinker with this, the more you will commingle and spaghetti-connect your code logic to the logic of the animator, and that is a Very Bad Thing™. If you change one it may result in really difficult-to-track down errors.