Search Unity

Basic animation clip question

Discussion in 'Animation' started by tylerlybb, Sep 5, 2016.

  1. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    I want to make cube that scales up when I click a button. The first thing I run into is this. Please help.

    1. Make a cube
    2. Make an animation on it called ScaleUp that scales from 1 to 2 (xyz)
    3. Add an Animation component on the cube (am I supposed to do this? I think I am)
    4. Drag the ScaleUp animation from my project into the top Animation field on the Animation component (I assume this is where you put the default clip, is that right?)

    I then get this error:

    Code (CSharp):
    1. The AnimationClip 'ScaleUp' used by the Animation component 'Cube' must be marked as Legacy.
    2. UnityEditor.DockArea:OnGUI()
    Am I doing this wrong to begin with? If I really do need to mark this clip as Legacy, how do I do that?
     
  2. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    Sorry. I inserted that error text as code which wasn't obviously not right.
     
  3. GrischaG

    GrischaG

    Joined:
    Apr 26, 2013
    Posts:
    40
    For scaling you could use a simple script instead of an animation!
     
  4. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    Okay, thanks. I may want to do that sometime. But I actually need to learn how to do this with animation clips because I will be making animations that are more 'artistic' eventually with this. This scale example is just a first step in the direction I need to go. Any help anyone?
     
  5. ionside

    ionside

    Joined:
    Apr 7, 2011
    Posts:
    43
    Hi Are you using a cube from unity or importing one from a 3d package?
    If it's an .fbx file you can go to the files import settings, go to the rig tab and choose Legacy from the type.
    (Don't have unity in front of me right now so can't remember the proper names).

    However, you might find you want to get accustomed to Mechanim, even with such a simple animation. It's easier in the long run when you want to set trigger events and transition through various animations.

    For something like this I would
    • create the scale up animation in the "Animation" window
    • create an animation controller and attach that to the object to use the animation
    • move the animation you created into the mechanim animation controller via the "Animator" window.
    • make that animation the default animation and it will start on Awake.
    See where that takes you!
     
  6. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    Thank you and sorry for not explaining better. I am creating this animation inside Unity, not importing from an external source. I tried following your steps but it's not working for me. Let me write my exact steps below so you can correct me where I'm wrong. Thanks!

    • Start brand new project
    • Create a cube, named Cube
    • Create a new animation on Cube inside the Animation window called ScaleUp (x, y and z scale from 1 to 2 across 1 second)
    Problem 1 - If I stop right here and press Play, the animation is playing on Cube by default over and over. This is not what I want. Eventually, I want to push Play, and have Cube just sitting there till I click a button and then it plays the ScaleUp animation one time. Regardless, I continue on, hoping I can resolve this later somehow.
    • Create a new animation controller in my project and drag it onto Cube in the scene's hierarchy
    • Open the animation controller in the Animator window (by default it comes with two states: "Any State" and "Entry")
    • Drag ScaleUp animation from the project into the Animator window (It automatically connects to the "Entry" state)
    • Create a new C# script in my project called TriggerAnim, with this code in it:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TriggerAnim : MonoBehaviour {
    5.  
    6.     public void AnimateNow()
    7.     {
    8.         GetComponent<Animation>().Play();
    9.     }
    10. }
    • Drag the TriggerAnim script onto Cube in my hierarchy
    • Create a new UI button in my scene
    • Create a new On Click event for that button
    • Drag Cube into that event and find the TriggerAnim > AnimateNow function
    If I press Play now, I see these problems:

    Problem 1 (already mentioned above)

    Problem 2 - When I click the button, I get this error:

    - MissingComponentException: There is no 'Animation' attached to the "Cube" game object, but a script is trying to access it. You probably need to add a Animation to the game object "Cube". Or your script needs to check if the component is attached before using it.
    So, assuming I need to add an Animation component to Cube, I continue on...
    • I add an Animation component to Cube
    • I drag ScaleUp into the top Animation field in that component
    As soon as I do that, I get a 3rd problem:

    Problem 3: In the Console window I get this error:
    The AnimationClip 'ScaleUp' used by the Animation component 'Cube' must be marked as Legacy.


    If I clear the Console window and press Play and then click the UI button, I see these problems:

    Cube is already scaling over and over by default (problem 1)

    I get two errors in the Console window:

    - The "Legacy" error mentioned in problem 3 above.
    - "Default clip could not be found in attached animations list."

    If I click the UI button I get the "Default clip could not be found" error again.
     
  7. GrischaG

    GrischaG

    Joined:
    Apr 26, 2013
    Posts:
    40
    Your Animation Component might have "Play automatically" checked. Thats why he starts playing the animation and you can uncheck it.

    Change your animation in the import settings to legacy.

    And then try GetComponent<Animation>().Play("ScaleUp", PlayMode.StopAll);

    You can make a public AnimationClip ScaleUp and drag your clip there. Then you can use:
    GetComponent<Animation>().Play(ScaleUp.name, PlayMode.StopAll);

    If you want to wait for other animations to finish you can use
    .PlayQueued: https://docs.unity3d.com/ScriptReference/Animation.PlayQueued.html

    Hope that helps,

    Grischa
     
  8. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    Thanks for the help, but I don't think I'm being understood here. I'm probably asking this in a confusing way and I apologize. Unchecking "Play automatically" doesn't fix the problem, and I can't change the import settings to Legacy because I'm not importing the animation, I'm creating it within Unity.

    I'm just trying to create a simple app using animation: push play and nothing happens yet, then click a button and the cube scales up. That's it.

    I'm attaching a zip file of my project. Please, someone help.
     

    Attached Files:

  9. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    Update: I found some info in the manual about why my setup is causing Unity to give me the 'Legacy" error. So, I'm making progress. But I'm still open to any suggestions in the meantime.
     
  10. jim_altvr

    jim_altvr

    Joined:
    Aug 10, 2015
    Posts:
    4
    You've got a couple problems that could be fixed by reading up on how Unity's Mecanim works. But since I have a minute and I'm waiting on some long Unity process to finish, I'll give you a head start:

    1) Your animation clip, 'ScaleUp' has its 'Loop Time' parameter ON. You'll want this unchecked. (Not sure why Unity defaults all animation clips to loop. Not a fan of this default.)
    upload_2016-9-12_1-24-46.png

    2) That animation clip is set as your default state in the ScaleUpController Animation Controller. You'll need to make a new Empty state, right-click-->Create State-->Empty. Then, right-click that new Empty state-->Set as Layer Default State

    3) Make a Transition (another right-click menu) from that Empty state to the one with your animation clip in it (ScaleUp)
    upload_2016-9-12_1-26-17.png


    4) Go to the Parameters Tab of the Animator window and press the + button to define a parameter (basically a function that will trigger the state to change, something like "DoIt"
    upload_2016-9-12_1-27-21.png

    5) Select that little white triangle transition and press the + button in there to create a Condition
    upload_2016-9-12_1-28-27.png

    6) Make sure to set that condition to "DoIt" (assuming it didn't do it automatically)

    Now, in your UI button, you don't need your script anymore. Instead:

    7) In your Button gameobject, scroll down to the On Click () section and change that dropdown to "Animator.SetTrigger"
    upload_2016-9-12_1-33-16.png

    8)Then set the object to be Cube (Animator) and the trigger to "DoIt"

    9)Press Play and see it work.

    10) Delete stuff you don't need
    like the 'Cube' animator controller and the TriggerAnim C# script.

    Hope this helps!
     
    theANMATOR2b likes this.
  11. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
  12. tylerlybb

    tylerlybb

    Joined:
    Jul 21, 2016
    Posts:
    51
    Thank you!!!!
     
  13. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Why isn't that bool exposed in the default editor?
     
    eses likes this.
  14. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Because we try to minimize the complexity of the UI by showing only relevant information.

    Switching from legacy to mecanim or vice-versa is not an operation that you do very often in a normal production as it involve many step to do a full conversion, still the option is available by script for advanced users who need to do the conversion.
     
  15. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    If users follow one of the very many tutorials online that shows how to use the Animation component, it will tell them to make an Animation clip, and then assign it to the Animation component.

    The user will do that, and be faced with a "you have to set the clip to legacy" error that they can't do anything about. That a bunch of settings are hidden in debug mode is not something that's well-documented, nor is it something that's well-known in the community. You're essentially spitting out an error that forces the user to google and find this specific thread.

    I'd say the information is very relevant.
     
    theANMATOR2b likes this.
  16. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    That error message a really bad error message, and we should have changed it a while ago.
    You can't reliably change an animation from Legacy to Generic and vice versa by just changing this flag. And you certainly can't change this at runtime. Exposing this as something that can be changed in the inspector would just add to the confusion.

    We have a task at the top of the pile right now to offer better feeback for (mostly) hidden animation properties (Legacy, Generic, Humanoid, Root Motion). Mostly in the inspector, but also in other windows.

    As for converting to and from Legacy, it should be a button in the inspector, or a right click option on the clip (or maybe both). This way, when it's not possible (or advisable), we can give proper feedback.

    When we have a proper solution for conversion, we should probably offer the conversion when someone attempts to drag or assign an animation that doesn't work for the component. Either a replacement or a copy.

    But yes, outdated tutorials are a problem.
     
    theANMATOR2b likes this.