|
I'm trying to write a script that cycles between showing different objects on screen, activating the current object, and deactivating the others. I'm using GameObject.GetComponentsInChildren() to do this, and it's giving the following error: InvalidCastException: Cannot cast from source type to destination type. LocationCustomization.ApplyChanges()(at Assets/MyAssets/Script/LocationCustomization.js:98) Here is the ApplyChanges function in question:
The objects are declared above as such:
The thing that's really confusing me is that I even tried copy/pasting the GetComponentsInChildren() code from the official documentation, replacing the component being called with what I'm trying to use, and it still gave the same error. Anyone see anything that I'm not?
(comments are locked)
|
|
The issue is that GetComponentsInChildren(type) returns Component[], not YourType[] What you can do is use GetComponentsInChildren.() instead This worked beautifully. Thanks a bunch.
Dec 30 '10 at 04:42 PM
user-7829 (google)
(comments are locked)
|

This won't solve your problem, but I believe that length should be capitalized: Length.