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 irulehyrule117 · Apr 27, 2014 at 06:30 PM · animationswordswing

there is no 'animation' attached to the gameobject but a script is trying to access it

I have an animation called "Swing" attached to an object called FreeCharacter_01 and a script that tells it to play when the Mouse0 button is pressed. Both of these, the animation and the script, are both attached to FreeCharacter_01, but when I hit the left mouse button, it says "there is no 'animation' attached to the gameobject but a script is trying to access it". I've searched all over the internet and other forums to find the answer and all of them just don't work out. I can't figure it out? Any ideas? (P.S. I am a massive noob) Also, here's the script.

 #pragma strict
 function Update()
 {
  if(Input.GetMouseButton (0))
  {
  
   animation.Play("Swing");
  }
 }
Comment
Add comment · Show 7
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 ZenithCode · Apr 27, 2014 at 07:59 PM 0
Share

Copy the animation. Lip in the array on the animator as the first element and this should work.

avatar image T-D-M-3 · Apr 27, 2014 at 11:45 PM 0
Share

Are you sure that the correct "swing" animation assigned to the object?

avatar image Jeff-Kesselman · Apr 27, 2014 at 11:50 PM 0
Share

It always helps if you show us the actual error 9and any stack trace if there is one) ins$$anonymous$$d of paraphrasing it.

At a wild guess, your object is actually made up of multiple objects and your script is on one child and the animation component on another.

Another wild guess is you are confusing animation, which is the legacy system, with animator which you need to use $$anonymous$$echanim to use.

A third wild guess, your import of the animations is set wrong in your model importer.

avatar image Chellebell1689 · May 03, 2015 at 11:37 PM 0
Share

Did you ever figure this out? I'm getting the same error. (And that's exactly what the error says)

avatar image T-D-M-3 · May 04, 2015 at 12:17 AM 0
Share

Did you try changing the animation mode?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by HD32 · May 04, 2015 at 10:20 AM

Here you go sir:

 var walkClip: AnimationClip;
 var anim: Animation;
 
 function Start() {
     anim = GetComponent.<Animation>();
     anim.AddClip(walkClip, "walk");
 }

I hope that helped. If you wanted to use C# here is the code:

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour {
     public AnimationClip walkClip;
     public Animation anim;
     void Start() {
         anim = GetComponent<Animation>();
         anim.AddClip(walkClip, "walk");
     }
 }

All of that is from the scripting API, so it should work. Just put incorporate that into the code you have right now and it should import the animation for use along side the script. =D

Comment
Add comment · 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
0

Answer by Crystalline · May 04, 2015 at 09:19 AM

The animation you are using is more than sure "legacy" type, in newer unity versions this wont work unless you mark it as legacy.

Solution:

  1. Select animation,go into debug mode, there is a little button with three lines in the right corner of the inspector , and then select "Legacy".

Comment
Add comment · 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

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

27 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 avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

animated sword + script 1 Answer

Swinging a sword without an animation... 1 Answer

Walking animation problem. 0 Answers

Animation Not Playing 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