- Home /
ThirdPersonCamera giving Invalid Cast Error in Android
I get this error
InvalidCastException: Cannot cast from source type to destination type. ThirdPersonCamera.Awake () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonCamera.js:52)
my platform is android
Presumably, this is happening because you are trying to cast from a type that isn't able to be converted into the desired type. I'd tell you how to fix it, but I don't know the exact circumstances unless you also post the line that caused the error.
In general, make sure you are specifying the type of every variable. That can help avoid this kind of problem.
the error leads me to this line "var characterController : CharacterController = _target.collider;" does this help?
Answer by syclamoth · May 11, 2012 at 08:54 AM
What type is '_target.collider'? Usually that returns a Collider, not a CharacterController. Try using
_target.GetComponent.<CharacterController>();
so do I swap that line i posted with yours. also someone down voted every one of my posts for no reson
This comment deserved to become an answer, thus I converted it - and this question didn't deserve a down vote, thus I upvoted it! Downvotes without explanation are totally useless.
thankyou that fixed it. sorry cant up vote you -6 kama DX
@qwertyqaz: I just looked through your "-1" questions and all actually deserve the downvote. You asked serveral things that has already been asked several times, that are well explained in the documentation or that is to argumentative ("can i do this or this").
This site is for specific questions about Unity that are useful to at least one other person. Usually all the "Fix my code"-questions doesn't directly meet this requirement, however if it's a good worded question and it's demonstrate a common problem it's ok. $$anonymous$$ost of your questions however are single-line questions with around 15 words.
If you need help, take the time to describe your problem. A lot people just come here for a quick personal help for free. Google doesn't $$anonymous$$d if you ask the same question 1000 times, but we aren't an automatic answering-machine for people that are simply to lazy to search first on their own.
Btw, i just like to add that a CharacterController IS a collider, a special kind of. It is derived from collider so if a CharacterController is attached to the gameobject, the collider property will return the CharacterController. However the type returned be the property is just Collider so it need to be casted into a CharacterController. Usually UnityScript does this under the hood, but on Android you are required to use strict typing.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Can't use Unity Remote 4 in Unity 4.5 1 Answer
Joystick won't move in Unity 0 Answers
native android plugin 0 Answers
Converting Android Axis to Unity Axis 0 Answers