x


Invisible Public Variable in Inspector

Is there any way of creating a public variable that doesn't show up in the inspector? We are currently working on a huuuge array (literally thousands of cells in it) and it works perfectly except from the fact that Unity's inspector tries to display it and crashed on a very regular basis.

The problem is that we need to make this variable public in order to have other scripts access it freely. But we cannot find a way to make the inspector ignore it.

We get the error message "too many heap sections" which means that somehow, somewhere Unity tries to sort the data and runs out of memory. We do not need to look at the data, so we'd like to NOT show it if possible.

BTW, when we close the inspector, Unity doesn't crash. That's how we know the source of the problem.

Any ideas?

more ▼

asked Oct 23 '10 at 06:48 PM

ilkejav gravatar image

ilkejav
48 1 1 5

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

2 answers: sort voted first

Hi.

You would do something like this:-

public float notHidden; // Displayed
[HideInInspector] // Hides var below
public float hidden;
more ▼

answered Oct 24 '10 at 08:18 AM

boymeetsrobot gravatar image

boymeetsrobot
587 7 10 22

Very useful! Since this is very much specific to the Unity platform, we didn't know this feature existed. Thanks!

Oct 25 '10 at 05:58 AM ilkejav
(comments are locked)
10|3000 characters needed characters left

The attribute HideInInspector might be of use, as well as NonSerialized if you don't want the values of the variables to be saved with the scene.

Note also that in general at least, it's not necessary for a variable to be public in order for it to be accessible from outside a class/struct. (In C#, for example, it's common to use properties to facilitate controlled access to protected or private data.)

more ▼

answered Oct 23 '10 at 11:36 PM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

wow, super! I think this may be what we're looking for. Really appreciated!

Oct 25 '10 at 05:57 AM ilkejav
(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

By RSS:

Answers

Answers and Comments

Topics:

x825
x467
x74

asked: Oct 23 '10 at 06:48 PM

Seen: 7324 times

Last Updated: Oct 23 '10 at 06:48 PM