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
0
Question by Tides · Jan 08, 2012 at 10:25 AM · guiarrayguicontent

GUIContent array issues.

Hey guys, just a small issue with a GUIContent array.

It would seem that it doesn't like to be re-sized. Here is my code:

     buttons.partyButtons = new GUIContent[skills.partySize[0]];
 
     for(var j : int; j < skills.partySize[0]; j++)
     {
        buttons.partyButtons[j].tooltip = currentParty[j].GetComponent(Info).fullName;
     }

So I'm resizing it to the value in a different array then adding the names of things in another array to the tool tips of the GUIContent array. When I run this however I'm give this error.

 NullReferenceException: Object reference not set to an instance of an object

That points to the line inside the for loop. If I remove the resizing of the array and re-size it manually it works no problem.

I found adding a yield between the re-size and the loop helped but only about 30% of the time.

Cheers.

Comment
Add comment
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

1 Reply

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

Answer by syclamoth · Jan 08, 2012 at 10:50 AM

Arrays can't be resized- what you are doing there is creating an entirely new array and replacing the old one!

The problem is that by creating the array of GUIContents, all it does is create a number of 'GUIContent' shaped 'holes'- not actual GUIContent objects. Assuming that you are going to change everything about the GUIContents, you need to use the line

 buttons.partyButtons[j] = new GUIContent("someText", currentParty[j].GetComponent(Info).fullName);

instead. Remember to set the rest of the GUIContent at the same time, since all three of its members will be null.

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 Tides · Jan 08, 2012 at 10:56 AM 0
Share

Thanks! When I said re-sized I was meaning re-creating, I knew that part. The funny thing is that I've done the above method for Transform arrays, etc with no issues what so ever.

Cheers.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to go around creating inventory with new GUI (4.6 Beta)? 1 Answer

Click on a button that is created post start. 0 Answers

changing GUI Button text with a string array 2 Answers

Select multiple objects 1 Answer

Unity Hangs/Crash when remove GUI Button. 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