Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PaxForce · Apr 24, 2014 at 06:01 PM · animationanimation.play

can't play simple animation

I've been searching the web for 4 hours but I still haven't figured out how to play a single #*!$#-ing animation on my GameObject. Help pls...

 using UnityEngine;
 using System.Collections;
 
 public class DuelPlayerControllerX : MonoBehaviour 
 {
 
     /*
     public AnimationClip attackTwoAnimation;
     public AnimationClip attackThreeAnimation;
     public AnimationClip dieOneAnimation;
     public AnimationClip dieTwoAnimation;*/
     public AnimationClip attackOneAnimation;
 
 
 
 void  Awake ()
 {
     
 }
 
 
 void  Update ()
 {
     
         if(Input.GetKeyDown (KeyCode.U))
         {
             Debug.Log ("U key pushed");
             animation.Play("attackOneAnimation");
         }
 
         
 }
 
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HalversonS · Apr 24, 2014 at 06:10 PM 0
Share

How old is the model and have you updated to a newer unity since importing it? You may need to check import settings (legacy vs newer methods).

You're getting the output "U key pushed" correct?

avatar image PaxForce · Apr 24, 2014 at 06:12 PM 0
Share

hi HalversonS, Yes, when I push U, the output says it has been pushed. The settings are set to legacy. And yes, I have the Unity updated.

avatar image HalversonS · Apr 24, 2014 at 06:17 PM 0
Share

Does the gameObject play the animation clip if you select it from the animation window within the editor? Also, are you getting any errors or is it just not playing the animation?

avatar image HalversonS · Apr 24, 2014 at 06:22 PM 0
Share

You're code is all fine. Plays animations on my objects (I'm a java guy so I had to check for myself, can't just eye it). It'll have to be either an import setting or something in the editor.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by BobbyDoogle · Apr 24, 2014 at 06:20 PM

Check that play on awake is not checked for your animations, as you are triggering them via code. Also check that the animations are set to loop (assuming you want to do this) from the import settings.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HalversonS · Apr 24, 2014 at 06:32 PM 0
Share

Play automatically won't matter as will if it's set to loop or not.

avatar image
0

Answer by HalversonS · Apr 24, 2014 at 06:42 PM

I dropped your script on a simple door of mine. -Fonted as Code Sample so you can read this easier without me spending 20 minutes editing it, none of this is code ;)-

Here are the settings I have (it plays just fine, as many times as I press 'U')

 Inspector components
   

Make sure your script is added to the object with the animations. The animations will be on the parent of the fbx file, so must the script be included there. You should see the animations next to Elements, the name there must match your script.

 Play Auto- doesnt matter
 Animate physics (mine are off)

culling type - always animate (mine is set to this, you may need it based on renders depending on what you're doing.)

 Import settings:
 -RIG-
 Animation Type: Legacy
 Generation: Stored in Root (deprecated)
 
 -Animations-
 Import ani - check
 Wrap mode- default
 anim. compreeesion - keyframe reduction
 errors all set to .5
 
 clips
 -----
 names with start to end. (door_open) is the name of the animation, so in script
 animation.Play("door_open");
 
 Add loop frame - unchecked
 wrap mode - default
 
   

If that doesn't work there is an issue with the export. Go back to maya/max/blender and re-export it and make sure the settings there are correct (such as animations being checked and the right amount of keyframes.

Also try adding a different object with a simple animation on it (cube rotating) and try it. Just to make sure it isn't an issue with your editor.

 Good luck!
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PaxForce · Apr 24, 2014 at 08:13 PM 0
Share

thanks for the advices guys, I'll look at these tomorrow.

avatar image PaxForce · Apr 26, 2014 at 07:45 AM 0
Share

HalversonS - thank you for the detailed walkthrough - as a beginner - that was exactly what I needed. Although it works now - I'm bit confused about how Unity works. I HAD TO USE THE NA$$anonymous$$ES OF THE ANI$$anonymous$$ATIONS, ins$$anonymous$$d the names of the variables I assigned the animations to.

The animations are attached to..or assigned to ..(how ever Unity works) to the model of the Warrior game object. Those animations are named eg. AttackOne, AttackTwo, AttackThree. Like this: Element 0 AttackOne Element 1 AttackTwo ...and so on...

I then declared a few variable like this: public AnimationClip attackOneAnimation; public AnimationClip attackTwoAnimation; ...and so on...

In the inspector I then assigned the AttackOne to attackOneAnimation, etc.

my question is: Why can't I work with the names of my variables in my script? Why do I have to use the names of the animations? Weird huh?

avatar image Cherno · Apr 26, 2014 at 12:35 PM 0
Share

Check if your animation is imported as "Legacy". If I try to import as Generic, Humanoid or anytheing else than Legacy, it won't work for me.

avatar image HalversonS · Apr 27, 2014 at 03:45 PM 0
Share

PaxForce, animation.play is actually gameObject.animation.play();

So it is searching the gameObject the script is on and looking for an animation, it then looks for and plays any animation on the gameObject that has that name.

If you want to use a variable you have to make sure you reference the gameObject. Having just "gameObject" (which is read in animation.play() -> gameObject.animation.play()) will always look at the gameObject the script is on. Something like this:

 var otherGOBJ : GameObject;
 function Start(){
    otherGOBJ = GameObject.Find("target");
    otherGOBJ.animation.Play();

Would be used for playing an animation on an object the script is not on.

Once you understand how objects are referenced and method overloading things click a lot easier. (at least those were my issues starting out)

Hope that helps!

(Remember to mark answers as answered so the Unanswered bin is reduced!)

avatar image HalversonS · Apr 27, 2014 at 03:48 PM 0
Share

Also, using a variable as an animation where the variable is a string, you wouldn't use quotations. So it would be just:

 animation.Play(attackOneAnimation);
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can the animation editor create local rotational data? 3 Answers

Animation2D help! 1 Answer

Adding animation clips via script 2 Answers

Animator.Play Not Playing Animation - Unity 5 1 Answer

Can't Animate 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges