Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mdagreda · Jan 03, 2013 at 06:44 PM · arraystringtextmesh

How do I get this string out of this array?

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.

         print(array1[counter]);
         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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Jan 04, 2013 at 02:12 PM 0
Share

You should just a

  List.<String> 

To store a variable size list of strings, don't use Array/ArrayList (see this.

    array1[counter].ToString() 

Will convert it.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Mr.Z · Jan 04, 2013 at 02:04 PM

 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: http://answers.unity3d.com/questions/27678/nullreferenceexception-object-reference-not-set-to.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mdagreda · Jan 04, 2013 at 02:26 PM 0
Share

It was the null at a lot of places. I replaced the null values with 0. Thanks.

avatar image
1

Answer by Aldo · Jan 03, 2013 at 07:03 PM

not the best way but do this

instanceMesh.text = ""+array1[counter];

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mdagreda · Jan 03, 2013 at 07:29 PM 0
Share

Thanks that got rid of the InvalidCastException: error, but I now have a "NullReferenceException: Object reference not set to an instance of an object" error. Any ideas what I could do? or what I should look for?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Find the length of a string in Javascript 1 Answer

Can't use remove with string[] ? 1 Answer

Iterating through multidimensional arrays 2 Answers

Comparing a string to an array extraction? 1 Answer

Get JSON array object string value 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges