- Home /
iTween: Cannot cast from source type to destination type.
Hi!
I use the following code to test the animation before writing a bunch of code:
Vector3 _position = new Vector3(326, -30, -1);
GameObject _boat = (GameObject)Instantiate(boatPrefab, _position, Quaternion.identity);
iTween.MoveTo(_boat, iTween.Hash("path", path, "speed", "10", "orienttopath", "true", "easetype", "easeInOutSine", "oncomplete", "complete"));
And got an error:
iTween.GenerateMoveToPathTargets () (at Assets/iTween/Plugins/iTween.cs:3580) iTween.GenerateTargets () (at Assets/iTween/Plugins/iTween.cs:3158) iTween.TweenStart () (at Assets/iTween/Plugins/iTween.cs:4598) iTween+c__Iterator8.MoveNext () (at Assets/iTween/Plugins/iTween.cs:6555) Any help will be appreciated.InvalidCastException: Cannot cast from source type to destination type.
Here is the sample with unwanted rotation of game object while it's moving along itween path. I see the same rotation for sprite and for cube. It rotates only "orienttopath" is set to "true".
Answer by Nanashi91 · Jan 12, 2013 at 05:11 PM
Hello. Your MoveTo-function has some invalid arguments. Try to write it like that:
public Transform boatPrefab;
// Use this for initialization
void Start () {
Vector3 _position = new Vector3(326, -30, -1);
GameObject _boat = (Instantiate(boatPrefab, _position, Quaternion.identity) as Transform).gameObject;
iTween.MoveTo(_boat, iTween.Hash("path", iTweenPath.GetPath ("path"), "speed", 2, "orienttopath", true, "easetype", iTween.EaseType.easeInOutSine, "oncomplete", "complete"));
}
void complete(){
Debug.Log ("complete");
}
I dont know if your variable path is a vector or anything else. I created a path with the name path. To create the path I used the iTweenPathEditor. The project of this example: Example1
If you want to make it without iTweenPath:
void Start () {
Vector3 _position = new Vector3(326, -30, -1);
Vector3[] path = new Vector3[2];
path[0] = new Vector3(326, -30, -1);
path[1] = new Vector3(320, -20, 0);
GameObject _boat = (Instantiate(boatPrefab, _position, Quaternion.identity) as Transform).gameObject;
iTween.MoveTo(_boat, iTween.Hash("path", path, "speed", 20, "orienttopath", true, "easetype", iTween.EaseType.easeInOutSine, "oncomplete", "complete"));
}
I made it as in samples: an array with points.
I tried your code, but: error CS0103: The name `iTweenPath' does not exist in the current context.
What is iTweenPath.GetPath? iTween has no such method and i have no iTweenPath (is it an extension to the iTween?).
After few tries i get another error:
NullReferenceException: Object reference not set to an instance of an object.
Although, i set a link to prefab in Inspector.
oh I'm sorry. Additionally to the iTween of the Unity Store I imported the iTween Path Editor. This includes also a script called iTweenPath. I edited my answer and added the link to the iTweenPathEditor and my example project.
I can´t reproduce your Exception. Can you post some code? $$anonymous$$aybe another reference is missing.
I made it with a iTween Path Editor (thanks for clue), but got another issue. This time with "orienttopath". It just doesn't work. If i set it to "false" — i see the sprite and animation, if "true" — see nothing. But i strongly need to set it "true".
I suspect that i need to contact with iTween developer to fix it.
Your answer
Follow this Question
Related Questions
What does this mean ? 1 Answer
BuildAssetBundle results in System.InvalidCastException 2 Answers
How to animate a moving platform GameObject? 2 Answers
Unknown Identifer 'iTween' 1 Answer