Trouble using animator

Hello:

I have a single .anim for a gameobject that I intent to use for a interaction hint, the problem i can’t control the clip thru script at runtime with animator component, like I used to do with the animation component. This gameobject is not a player, npc, item or anything like that, and it just need a single clip of animation, no more no less, it doesn’t need transitions, triggers, o params.

What am trying to do is play the single clip, like animator.play(), animator.stop(), set the time of the clip, and if this clip should loop or not. All this used to be posible with the animation component, but am forced to use animator this time, and I can’t get the same result.

This would be pretty easy to do with my Animancer plugin.

  • Control your animations through my AnimancerController component instead of the regular Animator.
  • animancer.Play(clip) returns an AnimancerState which can be used to control that animation, such as setting its time or speed.
  • I believe the AnimationClip.isLooping property is read-only so you need to set it in the animation’s import settings. But if you want to choose whether to loop or not via script, you can set it to loop by default and use the AnimancerState.OnEnd event to choose what you want to do (continue looping, or set the speed to 0 so it freezes in place, or whatever else you want).

Hey SilentSin
Not sure if you can help me with this, I cannot download your Animancer because of my Unity version.

I just want to animate 2D sprites by script. There are no transitions needed whatsoever. And how I made it now it takes AGES to do this via the Animator. I have not found a way to just tell my script to play an animation without any Animator. There is no way I will create an animator for each of my enemies.

I tried GetComponent().Play()/Blend() but then I get

When I do mark it as legacy (why exactly are 2D anims being called from a script legacy? or why would the animation clip need to be??), there are no more errors, but also no script call changes the sprite/animation.

I just want to use GetComponent().Play(“myAnimName”) and that’s it. I tried for hours already but it feels Unity wants to force me to use the Animator, which is a total overkill (make all the transitions for no reason etc).

I am even already considering avoiding the whole animation framework altogether and script my own (sprite = …)… Please help

The Animation component is Unity’s legacy animation system, which means it can only use legacy animation clips. For an animation imported as part of an FBX model you would go to the model and set it’s rig to legacy in its import settings. I have no experience with sprite animations though so I’m not sure how you set it for them. Most likely it’s in the inspector when you select the animation though.

Alternatively, you could make an AnimatorController with the states you need and control it using animator.Play(“StateName”). It’s still a pain to work with, but at least you don’t need to mess around with any transitions. That’s how I used to do it before I made Animancer.

I tried that as well. He will not play the clip!

With the Animation however, everything looks correct. When I Debug.Log the current clip it is the right one. Just it is not displayed in the game :frowning:
Also, whenever I have the animations as legacy, it never works. I have only made it work then they are not legacy, but then I need the Animator

I now installed the newest Unity version and tried your Animancer.
Worked from the first second :slight_smile:

Although I still need the Animator, I dont need any more stupid transitions.
Thank you :slight_smile:

1 Like