Before updating to Windows 10 you may need to return your Pro license. More information here

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.


more ▼

asked Jan 08, 2012 at 10:25 AM

avatar image

26 53 40 42

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Jan 08, 2012 at 10:50 AM

avatar image

19.4k 24 46 157

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.


Jan 08, 2012 at 10:56 AM Tides
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 08, 2012 at 10:25 AM

Seen: 1692 times

Last Updated: Jan 08, 2012 at 10:56 AM