Hi, I’m using the array class becuase I need to have an array that changes size dynamically so I’m trying to access a variable stored in it that should be a String and then assign that String to a TextMesh object’s text component. Here is the code I have so far.
instanceMesh.text = array1[counter];
But I get this error: InvalidCastException: Cannot cast from source type to destination type. Any ideas? The print works fine, but it gets stuck on the next line. If I left something out that would be helpful in solving this just post a comment and I’ll reply as quickly as I can. Thanks.
not the best way but do this
instanceMesh.text = “”+array1[counter];
InvalidCastException: error, but I now have a “NullReferenceException: Object reference not set to an instance of an object”
array1[counter] could be null at some point of your loop (I assume thats what u are using). Or if array1 is a class (I assume it’s not since the name doesn’t suggest that), you could be trying to set the value for the string instanceMesh.Text to be a class, which will never work. Or instanceMesh.text might not have been initialized. Also, you might wanna check this answer out: