- Home /
Resources.LoadAll - InvalidCastException: Cannot cast from source type to destination type.
Ok, I have this
public Texture [] arrayTargetTextures;
I’m tying to do this:
arrayTargetTextures =(Texture[]) Resources.LoadAll("candidates") ;
But getting this error:
Resources.LoadAll - InvalidCastException: Cannot cast from source type to destination type.
The docs here http://docs.unity3d.com/ScriptReference/Resources.LoadAll.html appear to be doing something similar:
Texture2D[] textures = (Texture2D[]) Resources.LoadAll("Textures");
Any idea what I’m doing wrong? I searched similar problems here but nothing seem to solve this issue. Thanks, in advance.
Are you getting this at runtime or at compile time?
Resources.LoadAll
returns an array of Object
s. It's not guaranteed what the actual type of these is. $$anonymous$$aybe one of them is not a Texture
, and that's why you're getting the error.
Try Resources.LoadAll<Texture>("candidates");
, without the cast.
Your answer

Follow this Question
Related Questions
ridiculous load time using Resources.Load() on android build 0 Answers
Assigning UV Map to model at runtime 0 Answers
I can't see a reason for this Array.Reverse() error 3 Answers
GUI layout Label Dimension issue 1 Answer
Cheapest/Easiest way to just draw a bunch of pixels right to the screen 0 Answers