• 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 smirlianos · Nov 08, 2012 at 06:45 PM · c#animationjavascriptfloatcrossfade

Animation.CrossFade help please

I want to make this line of the script work, but it gives me an error. This is the part of the script

 animation.CrossFade( Idle.name, 0.15f);

do I need to make a variable or what?

Comment
Add comment · Show 2
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 Landern · Nov 08, 2012 at 06:51 PM 0
Share

What is the error? Does Idle.name have a value? If so, does that property/field of Idle have a proper value that is an animation name on the model?

avatar image smirlianos · Nov 08, 2012 at 06:54 PM 0
Share

1 The name `Idle' does not exist in the current context

2 The best overloaded method match for `UnityEngine.Animation.CrossFade(string, float)' has some invalid arguments

3 Argument `#1' cannot convert `object' expression to type `string'

These are the errors. I'm not good at scripting so I don't know what do you mean in your comment! :)

3 Replies

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

Answer by Montraydavis · Nov 08, 2012 at 06:56 PM

Idle.name seems to be invalid for this circumstance.

Is your animations name "Idle.name" ?

Go to your Project folder, find the animation, and click it. In your inspector, look for the name, and use

 animation.CrossFade ( "Idle", 1.5f ) ; // Change Idle to whatever the name you got earlier.
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 smirlianos · Nov 08, 2012 at 07:07 PM 0
Share

Thanks dude!

avatar image
0

Answer by JustinRyder · Nov 08, 2012 at 07:00 PM

CrossFade(string, float) takes a string for the first parameter that is the name of the AnimationClip to fade to.

Assuming Idle references an AnimationClip on the Animation, then it should properly fade to it with your code. I would try hard coding the name of the clip first.

 animation.CrossFade("Idle");

If that doesn't work, then make sure that the script this is in is a component of the same GameObject that the Animation is a component of. If the Animation is a component of a parent or child of this script's GameObject, the animation reference could be null. If there are multiple Animations on the same GameObject, the animation reference could point to a different one.

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 Landern · Nov 08, 2012 at 06:57 PM

The second parameter or argument of the CrossFade method is correct. The first argument/parameter needs to be the name of the animation, example:

 animation.CrossFade("Run", 0.15f);
 
 or 
 
 animation.CrossFade("Idle", 0.15f);


The animation needs to exist, rather be imported with the model, you call that by it's name in the first argument either as a literal string or a property that contains the name as a string.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Animation/CrossFade difficulties, Animation won't CrossFade 0 Answers

How to make an animation finish after looping smoothly? 0 Answers

The problem of Enemy scale when he follow the player (script) . How to fix? 0 Answers

how to crossfade a animation and then loop it 1 Answer

Crossfade from ragdoll bones to animation 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