Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by VraunMM · Apr 21, 2016 at 06:14 PM · c#animationerrorgetcomponentfix

How to fix "no overload for method get component takes 1 arguments"

Ive got this irritating error which says "No overload for method 'getcomponent' takes 1 arguments.

here is the code

 using UnityEngine;
 using System.Collections;
 
 public class Character : MonoBehaviour {
 
     public float speed;
 
     public Animator player;
     public Animation front;
     public Animation frontIDLE;
     public Animation back;
     public Animation backIDLE;
     public Animation left;
     public Animation leftIDLE;
     public Animation right;
     public Animation rightIDLE;
 
     // Use this for initialization
     void Start () {
         player = gameObject.GetComponent<Animator> ();
 
     
     }
     
     // Update is called once per frame
     void Update () {
         //here is where I get all the errors v
         front = gameObject.GetComponent<Animation> ("WalkFront");
         frontIDLE = gameObject.GetComponent<Animation> ("WalkFrontIDLE");
         back = gameObject.GetComponent<Animation> ("WalkBack");
         backIDLE = gameObject.GetComponent<Animation> ("WalkBackIDLE");
         left = gameObject.GetComponent<Animation> ("WalkLeft");
         leftIDLE = gameObject.GetComponent<Animation> ("WalkLeftIDLE");
         right = gameObject.GetComponent<Animation> ("WalkRight");
         rightIDLE = gameObject.GetComponent<Animation> ("WalkFRightIDLE");
         //here is where I get all the errors ^
     }
 
     void WalkFront (){
         if (Input.GetKeyDown (KeyCode.W)) {
             front.Play ();
             transform.Translate (Vector2.up * speed * Time.deltaTime);
         }
 
         if (Input.GetKeyUp (KeyCode.W)) {
             front.Stop ();
             frontIDLE.Play ();
         }
     }
 }

im a beginner so plz help and quick!!!

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 jgodfrey · Apr 21, 2016 at 07:07 PM 0
Share

As the error says, you can't pass an argument (your "WalkFront", "WalkBack", etc strings) into the generic version of GetComponent. What exactly are you trying to do there? What do those strings represent?

The call in Start() is correct (notice, no argument). Like that, the call simply returns the Animator component found on the current game object (or null if none exists).

Again, what are you trying to do in the offending section of code?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by lockay · Sep 05, 2016 at 11:17 PM

@VraunMM

I can see what you are trying to do, but there is an easier way.

You are trying to make a variable that holds each clip, and then tell that clip to play. What you should do is access the Animation component on the GameObject, and use it to play animations.

The very first thing you need to do is add an Animation component to the GameObject. Then, adjust the array and drag in all of the animation clips. It should look something like this:alt text UPDATE: Uncheck "Play Automatically", unless you want the animation to run at start.

Don't add change the first variable, the one that says "Animation." Just leave it blank.

You should also add an Animator component to the GameObject, but you can leave it as is.

Now the code: First make a variable that represents the animation component. This isn't absolutely necessary, but it will make everything easier;

 public Animation anim;

In start, set the value of anim:

 void Start(){
     anim = GetComponent<Animation>();
 }

You don't need the GameObject when getting the component because you are already accessing the object that the script is on.

Now, you can tell the animations to play:

 void WalkFront(){
      if(Input.GetKeyDown(KeyCode.W)){
           anim.Stop("WalkFrontIdle");
           anim.Play("WalkFront");
      }
      if(Input.GetKeyUp(KeyCode.W)){
           anim.Stop("WalkFront");
           anim.Play("WalkFrontIdle");
      }
 }

Make sure that the animation clip name are spelled EXACTLY as they are in the inspector. WalkFront is different from walkFront and Walk Front.

Now repeat the previous code for walking backwards, sideways, etc. The WalkFront function won't actually run yet. It needs to be called in Update.

 void Update(){
      WalkFront();
      WalkRight();
      WalkLeft();
      WalkBack();
 }

Now the functions will run.

You may get an error similar to 'Animation clip "WalkFront" could not be found'. The main reason that I get the problem is when the clip isn't "Legacy". To make a clip Legacy, click on it in the Project/Assets, then change the Inspector mode to Debug, and check Legacy.alt text


screen-shot-2016-09-05-at-70240-pm.png (21.0 kB)
screen-shot-2016-09-05-at-71448-pm.png (26.9 kB)
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

6 People are following this question.

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

Related Questions

Using GetComponent without knowing the script name? 1 Answer

.IsPlaying does not exist? 1 Answer

The name animator does not exist in the current context... Help? 1 Answer

Referencing a function in a C# script 1 Answer

ERROR CS0119 C# GetComponent< > 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