I seem to be having a problem with my code at the moment, the error is “Cannot cast from source type to destination type”. I’ve got “#pragma strict” at the top of my script, but I’m not getting any further indications.
This is the code that I’m using:
foreach(Inventory.InventoryItem i in currentInventory.inventoryItems)
{
(IT THROWS THE ERROR HERE) ItemLibrary.ItemLibraryItem item = sessionLibrary.getItemByID(i.myID);
//GUI.Button(new Rect(x, y, 40, 40), sessionLibrary.getTextureById(item.textureIndex));
}
and this is the getTextureById function:
public ItemLibraryItem getItemByID(int id)
{
foreach(ItemLibraryItem item in libraryItems)
{
if(item.myID == id)
{
return item;
}
}
return new ItemLibraryItem("null", "null", 0, 0, 0, 0);
}
Could somebody give me some pointers on what might be happening, or how I could get rid of this damn error?
Could there be anyway there would be an ItemLibraryItem in the default namespace, are your includes all correct?
Try to call GetType() on what is returned from that function, but it’s somewhat hard to determine what could be off without knowing more. As it looks, it seems ok, but there could be odd naming, or overloading somewhere else causing it.
I never said there was. I was asking if it was an inner class, there’s nothing in what he posted to suggest it is… if it is not then that may be his error.
EDIT: Although I guess if that type wasn’t defined he’d be getting a different error message unless both types were defined.