How to make an 'idle' animation for UI elements?

hi,

OK, so this is probably a stupid question, but I’m stumped and tried searching but am not sure on the correct keywords to use, so I apologize in advance for the dumb question.

I simple UI and want to animate an Image so that it moves across the screen, just one time, and on demand only when I want it to.

I have my Image highlightedin the Hierarchy and open the animation window. I create a new animation where I move it along the X axis over some frames. BOOM - it works great!

Now I see that Unity automagically created an Animation Controller and assigned it to my Image object. It automatically created a state machine where it sets the initial state to this ‘MovingRight’ animation.

I unchecked the ‘Loop time’ checkbox on the animation and now its ALMOST perfect, but there’s one big problem: the animation plays automatically as soon as the Image instantiates. in my 3d animations, this is fine since I have an idle animation and I move into other states under parameter conditions. BUT here, there is NO '‘idle’ for this image bbox. I just want it to sit still and only move to the right on command.

What am I missing here? How do I prevent the UI Animation Controller from automatically running the animation right away?

thank you for any help!

@drewdough

hi there,

I’m not quite sure what you have done with your setup… but;

just and a method to some script, call it AnimatePlane or whatever - it should have a reference to your animated object / animator.

Add this method to button OnClick slot, which you want to use to trigger this effect.

When you press button, this method now gets called by button click.

In this script / method, do myAnimator.Play(); …and myAnimator should be a public variable, and you assign your plane’s animator to it.

thanks for the reply @ . So I shouldn’t use an animation controller at all is what you’re telling me ?

“it should have a reference to your animated object / animator”

when you say animator here you mean animation and not animation controller, riggt ?

@drewdough

Well if you are using legacy animation system, it too has Play method. It wouldn’t change things at all, you are just using Animation class instead of Animator.

I found this video here:

In this video he creates the idle animation. Basically, it’s just a single frame ‘‘animation’’ which sets the starting position of the UI element.

This is what I was looking for - BUT - I’'m wondering is this correct? When animating UI elements we have to create an idle animation for each element and use state machines? seems like a lot of work. I was hoping there was a way to just take an animation file, and give it to the UI element and have it play?