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 ByteVault · Dec 16, 2013 at 02:02 AM · animationerrorgameobjectplay

Animation play error. No animation attached.

I've been trying to play the animation I created inside of unity. I've added the animation to an empty gameobject called "SwingAnimation"(It's no longer empty). (I created the animation using a cube which I later removed to add a sword.)

The animation is working since its looping every time I test it out.

Picture showing the SwingAnimation GameObject in the Inspector view.

This is the code which I've been trying to play the animation with:

swing.js Attached to the Player.

 function Update () {
 
     if (Input.GetButton ("Fire1")) {
         
         GameObject.Find("SwingAnimation").animation.Play("swing");
 
     }
 
 }

I have also tried attaching the script directly on the gameobject containing the animation directly with:

function Update () {

 animation.Play();

}

But all I get is: There is no 'Animation' attached to the "SwingAnimation" game object, but a script is trying to access it.

I'm just scratching my head wondering how this can be? There is clearly an animation attached to the gameobject SwingAnimation. What am I doing wrong and how can I fix this?

Thank you in advance for any help you can provide and I apologize if I re-post the question on the matter but I could not find any solution for my problem amongst them. // N0tiC

Comment
Add comment · Show 1
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 Hyperion · Dec 16, 2013 at 02:39 AM 0
Share

Can you please open up that "Cube" Animator Controller and tell me if there is an animation inside?

If there is, then you must access it in a different way, which I will tell you once you answer.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Hyperion · Dec 16, 2013 at 01:45 PM

In order to access the animation, first click the plus button on the bottom left of the animation controller (Parameters) and add a parameter Bool called Fire. Then do the following inside the cube's Update function (I guess you'll have to add a new script): Write var myAnimator: Animator= GetComponent(Animator); This connects the script to the controller. Then write: if (Input etc...) myAnimator.SetBool("Fire",true);

Warning: in order for this to work, you must give the cube an idle animation. So delete the orange block state, add an idle, and make sure it becomes orange. Then add back the original cube animation. You can do all this by dragging by dragging animations into the Animator Controller.

Feel free to ask questions. Also, look up on YouTube a thing called Mecanim and find a Unity tutorial on it to show you the visual tricks.

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 Hyperion · Dec 16, 2013 at 02:13 PM 0
Share

Oh, I forgot to say: make a transition from the idle animation to the other animation by right clicking the idle one, clicking make transition, then left clicking the other animation. Then click that transition and changed the requirements from Exit Time into Fire.

avatar image ByteVault · Dec 16, 2013 at 02:28 PM 0
Share

Sounds great.. I'll definetly check it out later! To be honest, I was officially lost when I saw that Animator Controller. Never seen it before and I've used Unity3d In the past. Thanks, Hyperion, I'll "Accept the answer as correct" once I've tried and confirmed!

avatar image Hyperion · Dec 16, 2013 at 06:42 PM 0
Share

No problem. Glad to help! It took me a while to figure it all out, but it is worth it.

avatar image Hyperion · Dec 17, 2013 at 01:39 AM 0
Share

And here's a link to the Unity $$anonymous$$ecanim tutorial to guide you visually, if you haven't already seen it. http://www.youtube.com/watch?v=Xx21y9eJq1U

Also, somewhere in your script, you'll need to set the parameter Fire back to false in order to stop the animation...

avatar image ByteVault · Dec 17, 2013 at 05:52 PM 0
Share

It all worked like a sharm. Now that I know how it all works... There is work to be done! Thank you all!

Show more comments
avatar image
0

Answer by ByteVault · Dec 16, 2013 at 08:37 AM

I hope this is what you meant for me to do:

alt text

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 Hyperion · Dec 16, 2013 at 01:32 PM 0
Share

Okay, good. Now I can tell you how to access that animation. I'll do it in the answer.

avatar image
0

Answer by TheRichardGamer · Dec 16, 2013 at 09:11 AM

Did you notice that it doesn't have a animation component attached to it? That may just be your problem.

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 Hyperion · Dec 16, 2013 at 06:43 PM 0
Share

That's true, if you want to use the legacy animation system.

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

18 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

Related Questions

UCE0001: ';' expected. Insert a semicolon at the end 1 Answer

(C#) Problem with animations not playing 1 Answer

Animation Question Open Container 0 Answers

How to target a gameobject in C# to play animation 2 Answers

Play Animation on trigger enter 1 Answer


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