- Home /
transform array gives error. why?
I get an invalidcast excpetion error here and I can't figure out why. I have a transform variable, and a transform array. I populate the array when it wakes up but when I try to assign the variable to one of the transforms in the array I get an invalidcastexception error. anyone know why?
var respawnpoint : Transform; var respawnpoints = new Array (Transform);
function Awake() { //GET A LIST OF ALL SPAWN POINTS AND PUT THEM IN respawnpoints ARRAY. respawnpoints.push(gameObject.Find("SpawnPoint1").transform);
} function chooseSpawn() { for(i=0;i<respawnpoints.length;i++) { //deternmine which spawn point is best. respawnpoint = respawnpoints[i]; }
Answer by Loius · Oct 10, 2010 at 08:19 PM
You're not creating an Array of Transforms, you're creating an Array with one element - the type Transform.
Arrays are always arrays of Objects. You need to cast to Transform a la
respawnPoint = respawnPoints[i] as Transform;