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 FoxChaotica · Nov 09, 2013 at 09:13 PM · invalidcastexception

InvalidCastException

For some reason, this error keeps popping up

InvalidCastException: Cannot cast from source type to destination type.

(wrapper dynamic-method) UnityEngine.GameObject.GameObject$GetComponent$ (object,object[]) Boo.Lang.Runtime.RuntimeServices.Invoke (object,string,object[]) UnityScript.Lang.UnityRuntimeServices.Invoke (object,string,object[],System.Type) ButtonClick..ctor () (at Assets/scripts/ButtonClick.js:1) and i think i've got everything right, because it's working the way i want it to i've got this script on one object var Puzzpillar01 : PillarSpin = GameObject.GetComponent(PillarSpin.js);
function OnMouseDown(){ animation.Play("ButtonPress"); Puzzpillar01.spin(); } and this one on another var position : String = "0";
function spin () { if (position == "0") { position = "1"; animation.Play("Puzzpillarspin0"); } else if (position == "1") { position = "2"; animation.Play("Puzzpillarspin1"); } else if (position == "2") { position = "3"; animation.Play("Puzzpillarspin2"); } else if (position == "3") { position = "4"; animation.Play("Puzzpillarspin3"); } else if (position == "4") { position = "5"; animation.Play("Puzzpillarspin4"); } else if (position == "5") { position = "0"; animation.Play("Puzzpillarspin5"); } } and everything seems fine, but the error still keeps popping up. is there a problem with my code?
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Professor Snake · Nov 09, 2013 at 09:14 PM

You most likely need to replace GetComponent(PillarSpin.js) with GetComponent(PillarSpin). File extentions aren't included in the class names.

Comment
Add comment · Show 5 · 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 FoxChaotica · Nov 09, 2013 at 09:19 PM 0
Share

that breaks the script completely

avatar image Professor Snake · Nov 09, 2013 at 09:30 PM 0
Share

In which case. Try replacing GameObject.GetComponent with just GetComponent.

avatar image FoxChaotica · Nov 09, 2013 at 09:40 PM 0
Share

it gets rid of the invalidcastexception error, but now i get unityexception and argumentexception errors ins$$anonymous$$d

avatar image meat5000 ♦ · Nov 10, 2013 at 10:24 AM 0
Share

I don't think you are allowed to use GetComponent in a declaration outside of a function. Citation needed.

Try it in Start()

avatar image FoxChaotica · Nov 10, 2013 at 12:21 PM 0
Share

nope, that also breaks the script completely

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

Error on HSController.js 1 Answer

iTween: Cannot cast from source type to destination type. 1 Answer

Sprite Root Cannot cast from source type to destination type. 0 Answers

Sytem.InvalidCastException on Windows Phone 1 Answer

Door Script Help! 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